Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Minor Change Proposal for Classes 'Object' and 'Method'

Reply
Thread Tools

Minor Change Proposal for Classes 'Object' and 'Method'

 
 
Wolfgang Nádasi-Donner
Guest
Posts: n/a
 
      01-19-2007
Minor Change Proposal for Classes 'Object' and 'Method'
__________________________________________________ _____


I would like to make a small change suggestion on the class 'Method' by which
the method 'Object#method' is also affected.

Background:
___________

When creating a 'Method' object, it is not possible to receive the object
identification of the object which uses the 'Object#method' method (see 'Example
for Workaround' for details) by using some Method of class 'Method'.

It is useful for some applications to analyse later on which to which objects a
method is bound in an object of class 'Method'. In addition, it is simply
missing from my viewpoint, because it is an essential information (attribute) of
an object of class 'Method'.

A minor wish is an additional method for class 'Method', which returns the
contents of 'Method#to_s' as an Array containing two elements, the class-name
and the method-name without the textual border of 'Method#to_s'. It is easier
and less expensive to return this existing information by a method of class
'Method', than to use a regular expression later on to extract the information.

The method names used by here are only suggestions, since I needed names for the
example. Regarding definite names I have no emotions.

___________


>>>>> Example for Workaround >>>>>

class Object
alias :_org_method :method
def method(name)
method_object = self._org_method(name)
method_object.instance_id = self.object_id
method_object
end
end

class Method
attr_accessor :instance_id
def method_name
md = self.to_s.match(/Method:\s*([^#]+)#([^>]+)>/)
return md[1], md[2]
end
end

# Now an example

class Hugo
def hi
puts "An instance of Hugo says 'Hi!'"
end
end

my_hugo = Hugo.new
puts my_hugo.object_id # => 22497820 (for example)
myhi = my_hugo.method(:hi)
myhi[] # => An instance of Hugo says 'Hi!'
puts myhi.instance_id # => 22497820 (for example)
p myhi.method_name # => ["Hugo", "hi"]
>>>>> End of Example >>>>>


___________


Please inform me, if this is not the right place for a change proposal.

Wolfgang Nádasi-Donner (WoNáDo)
 
Reply With Quote
 
 
 
 
Wolfgang Nádasi-Donner
Guest
Posts: n/a
 
      01-26-2007
I don't know where to put this message into the very large discussion tree, so I
will put it here.

There is an argument against naming a method "receiver", which returns the
object which was bound to a method object.

>>>>> Example >>>>>


class Otto
def hi
puts "'Hi!' from an 'Otto' instance (#{self.inspect})"
end
end

class Hugo < Otto
def hi
puts "'Hi!' from an 'Hugo' instance (#{self.inspect})"
end
end

o = Otto.new
h = Hugo.new
bo = o.method(:hi)
bh = bo.unbind.bind(h)

h.hi # => 'Hi!' from an 'Hugo' instance (#<Hugo:0x2aea4dc>)
bh.call # => 'Hi!' from an 'Otto' instance (#<Hugo:0x2aea4dc>)
bo.call # => 'Hi!' from an 'Otto' instance (#<Otto:0x2aea478>)

>>>>> EoE >>>>>


In this example, the "Method" object "bh" contains (I temporary use this wording
for this example) the object "h", and the method "Otto#hi", which can be seen
in the output of "bh.call" - but - if ones sends the message "hi" to the object
"h" the method "Hugo#hi" will be used (see output for "h.hi").

This means, that for the object "h" contained in "Method" object "bh" a message
"hi" will not end up in calling "Otto#hi", because it finds "Hugo#hi".

It is misleading to call "h" the "receiver" of a message, that leads to the
invocation of "Otto#hi", because this cannot be done by any message in this example.

May be a different name is better to avoid confusion.

Wolfgang Nádasi-Donner
 
Reply With Quote
 
 
 
 
Wolfgang Nádasi-Donner
Guest
Posts: n/a
 
      01-26-2007
Sorry, I didn't recognize, that this was already named. More than 90 posts in
this discussion are very much...

Wolfgang Nádasi-Donner
 
Reply With Quote
 
Wolfgang Nádasi-Donner
Guest
Posts: n/a
 
      01-30-2007
Hi!

I don't know how you handle "Change Proposals" for Ruby. Implement them silently
or write somewhere an announcement, so I try to summarize what happens, as I
understood it.

Please correct me if I'm wrong, because I will report about the results in the
german Ruby forum.

I include my proposal for class "UnboundMethod" here, because I think it is
strongly related to this one.

----------------------------

As I understood, the will be some new methods available now or in the near
future in the repository (or the nightly snapshot). I'm not sure about the
chosen names, so please correct them.

==============
Class "Method"
==============

Public instance Methods:

receiver
--------
"receiver" returns the bound object of the method object. E.g. for "mo =
o.method(:m)" the expression "mo.receiver" will return "o".

name
----
"name" returns the name of the method object. E.g. for "mo = o.method(:m)" the
expression "mo.name" will return ":m" (symbol) or "'m'" (string).

owner
-----
"owner" returns the class which holds the method. E.g. for "mo = o.method(:m)"
the expression "mo.owner" will return "c", if the method ":m", that is bound to
"mo", is defined in this class. If the class is an anonymous class, it will be
handled correctly.

=====================
Class "UnboundMethod"
=====================

Public instance Methods:

name
----
"name" returns the name of the method object. E.g. for "mo = o.method(:m)" the
expression "mo.name" will return ":m" (symbol) or "'m'" (string).

owner
-----
"owner" returns the class which holds the method. E.g. for "mo = o.method(:m)"
the expression "mo.owner" will return "c", if the method ":m", that is bound to
"mo", is defined in this class. If the class is an anonymous class, it will be
handled correctly.

-----------------------

Is it a correct summary. There are so many messages in the discussion, that I
ended up in comfusion about the chosen names, sorry.

Wolfgang Nádasi-Donner
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
proposal, change self. to . Heiko Wundram Python 4 08-05-2008 06:28 PM
[Minor Change Proposal]Allow back reference with nest level in Onigurumafor Ruby again Wolfgang Nádasi-Donner Ruby 1 05-15-2007 03:12 PM
Help - client wants minor (??) last minute change kbutterly ASP .Net 1 02-11-2007 04:15 AM
Minor Change Proposal for Class 'Numeric' Wolfgang Nádasi-Donner Ruby 7 01-23-2007 12:10 AM
Minor Change Proposal for Classe 'UnboundMethod' Wolfgang Nádasi-Donner Ruby 0 01-19-2007 05:56 PM



Advertisments