[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Best name for "this method" ?

T. Onoma

9/27/2004 11:46:00 PM

Wondering what the conscensus is on the best name for "this method". Right now
I'm using #calling, taking after #binding, but I'm not so sure about it. I've
also considered #this or #thus, to be more along the lines of 'self'.

# Returns the current method or method name
def calling(firstclass=false)
m = /\`([^\']+)\'/.match(caller(1).first)[1]
return ( firstclass ? method( m ) : m.intern )
end

Also, will a method like this be implemented in future Ruby?

Thanks,
T.


67 Answers

Yukihiro Matsumoto

9/27/2004 11:58:00 PM

0

Hi,

In message "Re: Best name for "this method" ?"
on Tue, 28 Sep 2004 08:45:59 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:

|Also, will a method like this be implemented in future Ruby?

Possible. A good name for it is a must.

matz.


vruz

9/28/2004 12:02:00 AM

0

> Wondering what the conscensus is on the best name for "this method". Right now
> I'm using #calling, taking after #binding, but I'm not so sure about it. I've
> also considered #this or #thus, to be more along the lines of 'self'.

How about "me" ?


dblack

9/28/2004 12:10:00 AM

0

Gavin Sinclair

9/28/2004 12:23:00 AM

0

On Tuesday, September 28, 2004, 10:09:30 AM, David wrote:

> Hi --

> On Tue, 28 Sep 2004, trans. (T. Onoma) wrote:

>> Wondering what the conscensus is on the best name for "this method". Right now
>> I'm using #calling, taking after #binding, but I'm not so sure about it. I've
>> also considered #this or #thus, to be more along the lines of 'self'.
>>
>> # Returns the current method or method name
>> def calling(firstclass=false)
>> m = /\`([^\']+)\'/.match(caller(1).first)[1]
>> return ( firstclass ? method( m ) : m.intern )
>> end
>>
>> Also, will a method like this be implemented in future Ruby?

> If so, I hope it won't have the boolean flag. I think those flags,
> such as instance_methods(false), etc., are the most obscure, cryptic
> thing in Ruby. I'd like to see them disappear.

Amen. I can _never_ get a meaningful, predictable result out of those
damn *methods(flag) methods! At least, not on purpose. I've thought
more than once about writing my own set of methods to wrap those.
Pity thought hasn't become action.

Gavin




Ara.T.Howard

9/28/2004 12:23:00 AM

0

dblack

9/28/2004 12:37:00 AM

0

Gavin Kistner

9/28/2004 12:43:00 AM

0

On Sep 27, 2004, at 5:45 PM, trans. (T. Onoma) wrote:
> Wondering what the conscensus is on the best name for "this method".
> Right now
> I'm using #calling, taking after #binding, but I'm not so sure about
> it. I've
> also considered #this or #thus, to be more along the lines of 'self'.

In Javascript, there is 'caller' (the method which called the current
method) and 'callee' (a pointer to the current method).



Florian Gross

9/28/2004 12:47:00 AM

0

trans. (T. Onoma) wrote:

> Wondering what the conscensus is on the best name for "this method". Right now
> I'm using #calling, taking after #binding, but I'm not so sure about it. I've
> also considered #this or #thus, to be more along the lines of 'self'.

JavaScript uses callee for the first-class version.

> # Returns the current method or method name
> def calling(firstclass=false)
> m = /\`([^\']+)\'/.match(caller(1).first)[1]
> return ( firstclass ? method( m ) : m.intern )
> end

Personally, I'd dump the first-class logic and call it method_name. It
is easy enough to turn that into a Method anyway.

> Also, will a method like this be implemented in future Ruby?

I'm not sure about this. (Is it needed frequently?) But right now I'd
prefer Binding.of_caller to be in Ruby itself. After all it is needed
for wrapping eval() and it can not be done with a pretty interface in
plain Ruby. (It can be done in Ruby if you turn it inside out, e.g. make
it yield a value instead of returning it.)

> Thanks,
> T.

Regards,
Florian Gross

T. Onoma

9/28/2004 1:01:00 AM

0

On Monday 27 September 2004 08:49 pm, Florian Gross wrote:
> I'm not sure about this. (Is it needed frequently?) But right now I'd
> prefer Binding.of_caller to be in Ruby itself. After all it is needed
> for wrapping eval() and it can not be done with a pretty interface in
> plain Ruby. (It can be done in Ruby if you turn it inside out, e.g. make
> it yield a value instead of returning it.)

Binding.of_caller? Could you explain this more? I'm not sure to what you are
referring.

Thanks,
T.


T. Onoma

9/28/2004 1:11:00 AM

0

On Monday 27 September 2004 08:09 pm, David A. Black wrote:
> If so, I hope it won't have the boolean flag. I think those flags,
> such as instance_methods(false), etc., are the most obscure, cryptic
> thing in Ruby. I'd like to see them disappear.

Actually, I agree with you too. Since it's just a flag, perhaps using
meaningful symbols would be better?

methods(:public)
methods(:private)
methods(:protected)

methods(:no_ancestors)
methods(:ancestors_only)

methods(:class) # same as self.class.methods ?
methods(:singleton)

And they could be combined:

methods(:private, :protected)
methods(:singleton, :private)
methods(:private, :no_ancestors)

Etc.

T.