2

Closed

Adding a random object to Time which responds to to_f

description

(from Seo Sanghyeon [sanxiyn@gmail.com])   Time doesn't allow adding an object that responds to to_f:
 
c:\dev>irb
irb(main):001:0> now = Time.now
=> Tue May 12 23:58:47 -0700 2009
irb(main):002:0> class Foo
irb(main):003:1> def to_f
irb(main):004:2> 5.0
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> f = Foo.new
=> #<Foo:0x9d5088c>
irb(main):008:0> now + f
=> Tue May 12 23:58:52 -0700 2009
irb(main):009:0> exit
 
c:\dev>iirb
irb(main):001:0> now = Time.now
=> Tue May 12 23:59:23 -07:00 2009
irb(main):002:0> class Foo
irb(main):003:1> def to_f
irb(main):004:2> 5.0
irb(main):005:2> end
irb(main):006:1> end
=> nil
irb(main):007:0> f = Foo.new
=> #<Foo:0x00001e4>
irb(main):008:0> now + f
TypeError: can't convert IronRuby::Builtins::RubyObject into Float
    from (irb):8
    from :0:in `eval'
    from c:/ruby/lib/ruby/1.8/irb.rb:150:in `eval_input'
    from c:/ruby/lib/ruby/1.8/irb.rb:259:in `signal_status'
    from c:/ruby/lib/ruby/1.8/irb.rb:147:in `eval_input'
    from :0:in `loop'
    from :0:in `catch'
    from c:/ruby/lib/ruby/1.8/irb.rb:146:in `eval_input'
    from c:/ruby/lib/ruby/1.8/irb.rb:70:in `start'
    from c:/ruby/lib/ruby/1.8/irb.rb:69:in `start'
    from :0:in `catch'
    from c:/dev/ironruby/Merlin/Main/Languages/Ruby/Scripts/bin/iirb:12
irb(main):009:0>
 
Chronic has this problem: http://www.ruby-forum.com/topic/186769
Closed Jul 24, 2009 at 7:54 PM by jredville
confirmed

comments

jimmysch wrote May 13, 2009 at 8:07 AM

It's a pretty general protocol issue, and Shri has a fix for it: http://github.com/shri/ironruby/commit/09b25e8c573464dc5868ab2521bd631a013527c7

jimmysch wrote May 13, 2009 at 4:49 PM

Nevermind, this is not the fix ...

sborde wrote Jul 23, 2009 at 12:09 AM

Seems to be fixed now