From: Sam Roberts Date: 2007-03-22T08:14:37+09:00 Subject: Re: Extensions to ipaddr.rb On Thu, Mar 22, 2007 at 05:05:13AM +0900, Brian Candler wrote: > > Is this your intention? > > > > puts IPAddr.new("192.168.0.0") + "1" # => 192.168.0.1 > > > > I think you should be using #to_int, not #to_i. > > Two points in response to that: > > (1) The existing operator methods, like & and |, use to_i. For example: Fair enough. > (2) The main reason for to_i on the RHS is to be able to do things like I'm not sure the connection between the & operator and needing a #to_i method is, any object can be used with &, it doesn't have to be numeric in any way, c.f. Array#&. > a = IPAddr.new("192.168.0.123") > b = IPAddr.new("255.255.255.240") > c = a & b => # "255.255.255.240".to_i => 255 d = a & "255.255.255.240" => # :-( Unfortunate that duck-typing is not more consistently used in ruby's "standard" library collection, and that #to_s and #to_i are so frequently used instead of #to_str and #to_int, IMO. But nothing to do with your patch, as you say. Cheers, Sam