Skip to content

Instantly share code, notes, and snippets.

@lodestone
Created January 26, 2014 21:50
Show Gist options
  • Save lodestone/8639912 to your computer and use it in GitHub Desktop.
Save lodestone/8639912 to your computer and use it in GitHub Desktop.
SquishyI: Squeezes out numbers from a string.
irb(main):013:0> "$1,234,567".to_i
=> 0
irb(main):014:0> "$1,234,567".to_squishy_i
=> 1234567
module SquishyI
def to_squishy_i
to_s.scan(/[0-9]/).join.to_i rescue nil
end
end
[Fixnum, String, Float, NilClass].each {|klass| klass.send(:include, SquishyI) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment