[Ironruby-core] ConvertTo vs Cast
w.kelly at qut.edu.au
Tue Feb 5 04:08:33 EST 2008
From: ironruby-core-bounces at rubyforge.org [ironruby-core-bounces at rubyforge.org] On Behalf Of Peter Bacon Darwin [bacondarwin at googlemail.com]
Sent: Tuesday, 5 February 2008 6:37 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] ConvertTo vs Cast
Regarding the aside, you can pass Float, Bignum, Complex or any other class you choose to define to the Fixnum#+ operator so you do need an overload with object. I seem to remember it then coerces the fixnum to whatever the other type is and then calls + on the coerced object.
In Ruby 1.8.6:
'bind': bind argument must be an instance of Fixnum (TypeError)
Without looking at the code I can’t comment on the main thrust of the mail, but shouldn’t the local variable i be a Fixnum from the word go and therefore call the LessThan(int, int) method anyway?
Yes, LessThan(int, int) is called each time, but an unnecessary call is also made to method ConvertToInt32 every time around the loop to convert what is already an integer into an integer.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironruby-core