<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Ruby strings and is_int?</title>
	<atom:link href="http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/</link>
	<description>Agile Manager and Occasional Code Monkey</description>
	<pubDate>Sat, 06 Sep 2008 05:10:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Fred Bruneteau</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165734</link>
		<dc:creator>Fred Bruneteau</dc:creator>
		<pubDate>Mon, 14 Apr 2008 13:51:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165734</guid>
		<description>The Robin's tip is interesting because it's realy test the numeric value.
Be careful of the method to_i( ) of the class String, I have detected this behaviour :
&lt;code&gt;
irb &#62; "47azerty".to_i
=&#62; 47
irb &#62;
&lt;/code&gt;
The method to_i( ) only used the digits at the beginning of the string.

N.B. : I use Ruby 1.8.6</description>
		<content:encoded><![CDATA[<p>The Robin&#8217;s tip is interesting because it&#8217;s realy test the numeric value.<br />
Be careful of the method to_i( ) of the class String, I have detected this behaviour :<br />
<code><br />
irb &gt; "47azerty".to_i<br />
=&gt; 47<br />
irb &gt;<br />
</code><br />
The method to_i( ) only used the digits at the beginning of the string.</p>
<p>N.B. : I use Ruby 1.8.6</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Berther</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165623</link>
		<dc:creator>Matt Berther</dc:creator>
		<pubDate>Thu, 03 Apr 2008 17:19:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165623</guid>
		<description>@rik: I think I need to spend more time in IRC and some more time with Ruby in general. I think the point of my post was that I was just surprised that this was not available in Ruby already. Your method for doing this is exactly the same as I would do it in my .NET projects.</description>
		<content:encoded><![CDATA[<p>@rik: I think I need to spend more time in IRC and some more time with Ruby in general. I think the point of my post was that I was just surprised that this was not available in Ruby already. Your method for doing this is exactly the same as I would do it in my .NET projects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rik Hemsley</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165622</link>
		<dc:creator>Rik Hemsley</dc:creator>
		<pubDate>Thu, 03 Apr 2008 07:49:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165622</guid>
		<description>Converting a string to an integer is FAQ #1 on IRC.

The usual answer given is:

Integer(s) rescue default

... where default is whatever you want the result to be if s won't convert to an Integer.</description>
		<content:encoded><![CDATA[<p>Converting a string to an integer is FAQ #1 on IRC.</p>
<p>The usual answer given is:</p>
<p>Integer(s) rescue default</p>
<p>&#8230; where default is whatever you want the result to be if s won&#8217;t convert to an Integer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Berther</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165620</link>
		<dc:creator>Matt Berther</dc:creator>
		<pubDate>Thu, 03 Apr 2008 04:53:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165620</guid>
		<description>@robin: thanks for the tips. I actually prefer the first, since I dont end up monkey-patching the string class unnecessarily. I also found that I need to validate my page parameter for nil as well, so the line looks like this:

page = "1" if not page.nil? and page.to_i &#60; 1</description>
		<content:encoded><![CDATA[<p>@robin: thanks for the tips. I actually prefer the first, since I dont end up monkey-patching the string class unnecessarily. I also found that I need to validate my page parameter for nil as well, so the line looks like this:</p>
<p>page = &#8220;1&#8243; if not page.nil? and page.to_i &lt; 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robin Curry</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165619</link>
		<dc:creator>Robin Curry</dc:creator>
		<pubDate>Thu, 03 Apr 2008 04:50:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165619</guid>
		<description>Ha, here's another way to do it (can't take credit for this, I found it somewhere else):

def is_int? self.to_i.to_s == self end</description>
		<content:encoded><![CDATA[<p>Ha, here&#8217;s another way to do it (can&#8217;t take credit for this, I found it somewhere else):</p>
<p>def is_int? self.to_i.to_s == self end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robin Curry</title>
		<link>http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165618</link>
		<dc:creator>Robin Curry</dc:creator>
		<pubDate>Thu, 03 Apr 2008 04:42:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mattberther.com/2008/04/02/ruby-strings-and-is_int/#comment-165618</guid>
		<description>to_i will convert a non-numeric string value to 0, so you could do something like:

page = "1" if page.to_i &#60; 1</description>
		<content:encoded><![CDATA[<p>to_i will convert a non-numeric string value to 0, so you could do something like:</p>
<p>page = &#8220;1&#8243; if page.to_i &lt; 1</p>
]]></content:encoded>
	</item>
</channel>
</rss>
