From: "David A. Black" Date: 2003-12-17T23:42:29+09:00 Subject: Re: UnboundMethods Useless? Hi -- On Wed, 17 Dec 2003, Peter wrote: > > I don't know what you mean by (ir)reversible, but the point is that > > it's meaningless to talk about arbitrary objects being able to do > > arbitrary things. For example (and Guy has already given some), > > String#strip removes whitespace. What would it mean to remove > > whitespace from a Hash or a Fixnum or a MyThing? And more to the > > point, what would happen if > > > > I don't mean: "Could such objects have some method called 'strip' > > which made sense for them?" because that's not what you're suggesting. > > What you're suggesting is that String#strip, Array#join, Thread#join, > > IO#readlines, Regexp.escape, MyThing#some_method, and every other > > method written for any purpose in Ruby should, without change or > > adaptation, work for any Ruby object. > > By the same reasoning, Ruby is suggesting that any module makes sense in > any class/object, because you can include a module in any class you'd > like. With freedom comes the possibility of doing something wrong, but > that doesn't make freedom wrong, now does it? There's a difference between freedom and a free-for-all or chaos. In the case of module inclusion, of course you can do things that don't work: module M def x; strip; end end class C include M end C.new.x # undefined method strip but you've got a mechanism -- a language design -- in place which handles errors. (And of course there's much more to that design.) If you simply cut-and-paste methods (including core methods) from one object to another, you're bypassing this. David -- David A. Black dblack@wobblini.net