Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.18 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Strip leading zeroes, check if input matches after conversion to integer
  2. class String
  3.   def is_num?
  4.     self.to_i.to_s == self.gsub(/^0+/, '')
  5.   end
  6. end
  7.  > "045".is_num?
  8.  => true