From: Robert Klemme Date: 2010-11-12T16:59:02+09:00 Subject: Re: what's an object? On Fri, Nov 12, 2010 at 8:29 AM, Josh Cheek wrote: > On Thu, Nov 11, 2010 at 9:05 PM, Chad Perrin wrote: > >> On Thu, Nov 11, 2010 at 04:51:46PM +0900, Josh Cheek wrote: >> > On Wed, Nov 10, 2010 at 11:55 PM, timr wrote: >> > > >> > > Alex said everything is an object--including an instance of a class, >> > > the class itself, its methods. I agree up until he mention methods as >> > > objects. I don't think that can be demonstrated. For instance, we >> > > cannot get the object_id of a method. '+.object_id' doesn't work. So, >> > > I don't agree that methods are objects. >> > > >> > 1.method('+').object_id >> >> 1.method('+') is not the same as 1.+, so your example does not prove + is >> a method.  The object ID you get with 1.method('+').object_id is actually >> the object ID of the object that is returned by the method "method" when >> it is passed an argument of the string "+".  That is not the same thing >> as an object ID for the + method itself. >> >> Here's a thought experiment for you: >> >> If + is an object, and 1.method('+') returns that object so that you can >> get its object ID with 1.method('+').object_id, this should work: >> >>    > foo = 1.method('+') >>    > foo(3) >>    4 >>    > >> >> Fire up irb and try it, now.  It doesn't work. >> >> Instead, if you want to use it, you need to do this: >> >>    > foo = 1.method('+') >>    > foo.call(3) >>    4 You can even do irb(main):001:0> foo = 1.method '+' => # irb(main):002:0> foo[3] => 4 which is pretty close to foo(3). >> That's because a "method object" is not a method; it is a proc that wraps >> the method and its scope context. Exactly. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/