[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Yukihiro Matsumoto

1/19/2007 4:53:00 PM

Hi,

In message "Re: Minor Change Proposal for Classes 'Object' and 'Method'"
on Sat, 20 Jan 2007 01:15:05 +0900, Wolfgang Nádasi-Donner <wonado@donnerweb.de> writes:

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

|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"]

Why object_id? Isn't it more useful to return the receiver itself,
e.g.

myhi.receiver # => #<Hugo:0xb7d5ff40>

?

And why should method_name return combination of class name and method
name? I think the method_name should return the method name only
("hi" for this case). It may be useful to implement separate method
to get a class that holds the method.

matz.


4 Answers

WoNáDo

1/19/2007 5:45:00 PM

0

Yukihiro Matsumoto schrieb:
> Why object_id? Isn't it more useful to return the receiver itself,
> e.g.
>
> myhi.receiver # => #<Hugo:0xb7d5ff40>
>
> ?
>
> And why should method_name return combination of class name and method
> name? I think the method_name should return the method name only
> ("hi" for this case). It may be useful to implement separate method
> to get a class that holds the method.

I agree, because I'm only interested in the information at all. If you find a
better format or better way to present it, its fine.
One question is open for 'myhi.receiver # => #<Hugo:0xb7d5ff40>'.

First, the format requires a pattern matching on the result, if the object-id
ist needed only. May be two seperate methods are better, as you suggested for
'method_name'.

In additon, a format for the seperate method, that returns information about the
class that holds the method, may be complicated for singleton methods. An
example is '#<Method: #<Hugo:0x2ae6e54>.private_hi>'.

Wolfgang Nádasi-Donner (WoNáDo)



Kalman Noel

1/19/2007 5:49:00 PM

0

Yukihiro Matsumoto:
> And why should method_name return combination of class name and method
> name? I think the method_name should return the method name only
> ("hi" for this case).

I agree here. Furthermore I think that #name would be a better name, in
analogy to Module#name.

Kalman

Kalman Noel

1/19/2007 5:50:00 PM

0

Wolfgang Nádasi-Donner:
> One question is open for 'myhi.receiver # => #<Hugo:0xb7d5ff40>'.
>
> First, the format requires a pattern matching on the result, if the object-id
> ist needed only.

May you elaborate? Where do you need pattern matching here?

Kalman

WoNáDo

1/19/2007 6:15:00 PM

0

Kalman Noel schrieb:
> Wolfgang Nádasi-Donner:
>> One question is open for 'myhi.receiver # => #<Hugo:0xb7d5ff40>'.
> May you elaborate? Where do you need pattern matching here?

myhi.receiver.match(/:([^>]+)>/)[1] # => "0xb7d5ff40"

and I need 'eval' to compare the textual presentation of the object-id with the
object-id I receive from "Object#object_id" (or I have to convert this result to
an textual hex-presentation)