<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ABAP101 &#187; Ruby</title>
	<atom:link href="http://abap101.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://abap101.com</link>
	<description>ABAP &#124; Open Source &#124; Agile &#124; Programação</description>
	<lastBuildDate>Wed, 01 Feb 2012 01:27:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Como verificar se um arquivo existe em Ruby</title>
		<link>http://abap101.com/2009/03/04/como-verificar-se-um-arquivo-existe-em-ruby/</link>
		<comments>http://abap101.com/2009/03/04/como-verificar-se-um-arquivo-existe-em-ruby/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 14:13:03 +0000</pubDate>
		<dc:creator>Flávio Furlan</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://abap101.com/?p=109</guid>
		<description><![CDATA[No projeto Reploy, o SHA1 do último commit repackaged fica guardado em arquivo oculto chamado &#8220;.last_repack&#8221;. Quando o script é executado pela primeira vez, esse arquivo não existe. Então se eu tentar simplesmente abrir o arquivo: # Get the latest sha last_sha = File::read&#40; '.last_repack' &#41; Se o arquivo não existir, terei o seguinte erro: [...]]]></description>
			<content:encoded><![CDATA[<p><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service facebook_like" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;layout=button_count&amp;show_faces=false&amp;width=75&amp;action=like&amp;colorscheme=light&amp;height=20&amp;ref=addtoany" scrolling="no" style="border:none;overflow:hidden;width:90px;height:21px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;counturl=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;count=horizontal&amp;text=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" scrolling="no" style="border:none;overflow:hidden;width:130px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service twitter_tweet" src="http://platform.twitter.com/widgets/tweet_button.html?url=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;counturl=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;count=horizontal&amp;text=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" scrolling="no" style="border:none;overflow:hidden;width:130px;height:20px"></iframe><!--<![endif]--><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;size=medium&amp;count=true" scrolling="no" style="border:none;overflow:hidden;width:90px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;size=medium&amp;count=true" scrolling="no" style="border:none;overflow:hidden;width:90px;height:20px"></iframe><!--<![endif]--><a class="a2a_button_google_gmail" href="http://www.addtoany.com/add_to/google_gmail?linkurl=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;linkname=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" title="Google Gmail" rel="nofollow" target="_blank"><img src="http://abap101.com/wp-content/plugins/add-to-any/icons/gmail.png" width="16" height="16" alt="Google Gmail"/></a><a class="a2a_button_wordpress" href="http://www.addtoany.com/add_to/wordpress?linkurl=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;linkname=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" title="WordPress" rel="nofollow" target="_blank"><img src="http://abap101.com/wp-content/plugins/add-to-any/icons/wordpress.png" width="16" height="16" alt="WordPress"/></a><a class="a2a_button_blogger_post" href="http://www.addtoany.com/add_to/blogger_post?linkurl=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;linkname=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" title="Blogger Post" rel="nofollow" target="_blank"><img src="http://abap101.com/wp-content/plugins/add-to-any/icons/blogger.png" width="16" height="16" alt="Blogger Post"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fabap101.com%2F2009%2F03%2F04%2Fcomo-verificar-se-um-arquivo-existe-em-ruby%2F&amp;title=Como%20verificar%20se%20um%20arquivo%20existe%20em%20Ruby" id="wpa2a_2"><img src="http://abap101.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p><p>No projeto Reploy, o SHA1 do último commit repackaged fica guardado em arquivo oculto chamado &#8220;.last_repack&#8221;. Quando o script é executado pela primeira vez, esse arquivo não existe.</p>
<p>Então se eu tentar simplesmente abrir o arquivo:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Get the latest sha</span>
last_sha = <span style="color:#CC00FF; font-weight:bold;">File</span>::read<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'.last_repack'</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Se o arquivo não existir, terei o seguinte erro:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">repack.<span style="color:#9900CC;">rb</span>:<span style="color:#006666;">5</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#996600;">`read': No such file or directory - .last_repack (Errno::ENOENT)
from repack.rb:5</span></pre></div></div>

<p>Para resolver isso, usei o seguinte comando no programa:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'.last_repack'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Uso o método exist? para verificar se o arquivo existe. O &#8220;?&#8221; em Ruby indica que o método retornará apenas true ou false.</p>
]]></content:encoded>
			<wfw:commentRss>http://abap101.com/2009/03/04/como-verificar-se-um-arquivo-existe-em-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

