J
Jason Lillywhite
I want to raise an ArgumentError, "Function only takes numeric objects."
if a non-numeric argument is passed to the existing Ruby method,
Numeric.ceil.
#Here is my feeble attempt to extend Ruby:
irb(main):001:0> class Numeric
irb(main):002:1> alias ld_ceil :ceil
irb(main):003:1> def ceil
irb(main):004:2> raise ArgumentError,
irb(main):005:2* "function only takes numeric objects." unless
self.is_a? Numeric
irb(main):006:2> self.old_ceil
irb(main):007:2> end
irb(main):008:1> end
=> nil
#But that does not work - I can't get past the call on the object
irb(main):009:0> "foo".ceil
NoMethodError: undefined method `ceil' for "foo":String
from (irb):9
Could someone point me in the right direction? Thank you.
if a non-numeric argument is passed to the existing Ruby method,
Numeric.ceil.
#Here is my feeble attempt to extend Ruby:
irb(main):001:0> class Numeric
irb(main):002:1> alias ld_ceil :ceil
irb(main):003:1> def ceil
irb(main):004:2> raise ArgumentError,
irb(main):005:2* "function only takes numeric objects." unless
self.is_a? Numeric
irb(main):006:2> self.old_ceil
irb(main):007:2> end
irb(main):008:1> end
=> nil
#But that does not work - I can't get past the call on the object
irb(main):009:0> "foo".ceil
NoMethodError: undefined method `ceil' for "foo":String
from (irb):9
Could someone point me in the right direction? Thank you.