On Sun, Jun 24, 2012 at 9:20 PM,  <[email protected]> wrote:
> Am 24.06.2012 20:37, schrieb luke gruber:
>
>>> Here an example method that I use from time to time:
>>>
>>> class String
>>>    def integer?
>>>      !!(self =~ /\A[+-]?[0-9]+\Z/)
>>>    end
>>> end
>>>
>>> Regards,
>>> Marcus
>>
>>
>> Hey, this can be made a bit cleaner by doing:
>>
>>    /regex/ === 'string'

Or even

def integer?
  Integer(self) rescue nil
end

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to