Skip to content

Instantly share code, notes, and snippets.

@mperham
Created February 10, 2014 19:43
Show Gist options
  • Save mperham/8922782 to your computer and use it in GitHub Desktop.
Save mperham/8922782 to your computer and use it in GitHub Desktop.
Rubby numeric handling
> require 'bigdecimal'
=> true
> Float('foo')
ArgumentError: invalid value for Float(): "foo"
from (irb):2:in `Float'
from (irb):2
from /Users/mikep/.rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'
> Integer('foo')
ArgumentError: invalid value for Integer(): "foo"
from (irb):3:in `Integer'
from (irb):3
from /Users/mikep/.rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'
> BigDecimal('foo')
=> #<BigDecimal:7fccf7178fb0,'0.0',9(9)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment