From: Dan Doel Date: 2003-08-22T18:31:33+09:00 Subject: Re: What attracts me to Ruby MikkelFJ wrote: >>This is another thing that seems strange to me. Ruby's object >>orientation has never seemed intrusive to me. You can write anything as >>if it were a non-OO language, and things just live in the "main" >>namespace. I can't think of any ways in which Ruby's OO nature made it >>more difficult to do something. Can you think of a quick example? >> >> > >You can't pass a reference to function around - not without involving less >elegant Proc objects or similar. > >Also I really would like delegates in Ruby - passing a reference to a method >such that it knows the class it belongs to. >This is highly useful. I know it can be implemented (an old discussion), but >it would be very nice to have in the core language. > It is: class Foo def x @x end def x=(value) @x = value end end f1 = Foo.new f2 = Foo.new f1.x = 5 f2.x = 6 meth1 = f1.method(:x) meth2 = f2.method(:x) p meth1.call p meth2.call It's not as transparent as in Python (calling Proc/Method objects don't use the same syntax as normal method calls) but there's no reason you need that for anything other than syntactic consistency, and adding that would cause more problems than it would solve. - Dan