From: "Wolfgang Nádasi-Donner" Date: 2007-01-22T01:20:06+09:00 Subject: Re: Minor Change Proposal for Classes 'Object' and 'Method' dblack@wobblini.net schrieb: > In any case, > I included it because it demonstrates that there's a "meta" or > two-step way of getting a message to an object, but that a.method(:x) > isn't such a technique. "mo = a.method(:x)" creates a new object "mo" of class "Method", which contains the object "a" and a reference (or however to name this) to a method. To find the method, ":x" will be interpreted as a message "x" to object "a", but the corresponding method will not be executed, but referenced in the new Method object. When writing "mo.call" the object "a" will be enforced to use the method referenced by "mo" without any method lookup. This means, that the actual state of object "a" will be used to call a method, which may be overwritten in the meantime. The name "receiver" for a method of class "Method", which returns the object for which "method" was called makes some sense, because in the moment "method" was called, the referenced method inside the "Method" object would be executed by the object when receiving the message named by the parameter for the "method" method. >>>>> Code >>>>> class Otto attr_accessor :id def hi puts "'Hi!' from an instance of 'Otto' with id #{self.id}" end def initialize(id) self.id = id end end otto = Otto.new(42) myhi = otto.method(:hi) otto.hi # => 'Hi!' from an instance of 'Otto' with id 42 myhi.call # => 'Hi!' from an instance of 'Otto' with id 42 class Otto def hi puts "'Hihihi!' from an instance of 'Otto' with id #{self.id}" end end otto.id = 84 otto.hi # => 'Hihihi!' from an instance of 'Otto' with id 84 myhi.call # => 'Hi!' from an instance of 'Otto' with id 84 class Otto remove_method :hi end myhi.call # => 'Hi!' from an instance of 'Otto' with id 84 otto.hi # => MethodSuchReihe.rb:33: undefined method `hi' for # => # (NoMethodError) >>>>> EOC >>>>> Wolfgang N�dasi-Donner