Best name for "this method" ?

T

trans. (T. Onoma)

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.
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Best name for "this method" ?"

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

Possible. A good name for it is a must.

matz.
 
V

vruz

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" ?
 
D

David A. Black

Hi --

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.


David
 
G

Gavin Sinclair

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
 
A

Ara.T.Howard

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.

in C this is known as __FUNCTION__. so perhaps 'function'. this could be
o.k. if it were a method of Binding => Binding#function

also useful would be

Binding#functions

to return a list of the call stack function names

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 
D

David A. Black

Hi --

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.

in C this is known as __FUNCTION__. so perhaps 'function'. this could be
o.k. if it were a method of Binding => Binding#function

Hmmmm... then we'd have proc, Proc, lambda, block, closure, method,
*and* function :)


David
 
G

Gavin Kistner

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).
 
F

Florian Gross

trans. (T. Onoma) said:
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

trans. (T. Onoma)

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

trans. (T. Onoma)

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.
 
T

trans. (T. Onoma)

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.

Then what about #called for just the method name?

def my_method
p called
end

T.
 
T

trans. (T. Onoma)

How about "me" ?

My initial reaction was that it's too much like self. But now that I've given
it some more thought it probably is an excellent choice.

1) It's a pronoun
2) It's very short
3) It has some semantic value, i.e. as in (me)thod
4) It not really used for anything else (AFAIK)

T.
 
G

Gavin Sinclair

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


methods:)class) # same as self.class.methods ?
methods:)singleton)
And they could be combined:
methods:)private, :protected)
methods:)singleton, :private)
methods:)private, :no_ancestors)

Nice idea. I'm considering putting a bit of effort into an API for
querying the methods of an object. It's an easy thing to do, but it's
gotta be done well. Anyway...

m = Methods["foo"] # -> Methods object
m.public
m.protected
m.private
m.singleton
m.no_ancestors
m.ancestors_only
m.class # name clash :(

m.public:)no_ancestors)
m.singleton:)private)

m.query:)public, :no_ancestors)
m.query:)singleton, :private)

Then a similar thing for instance methods of a class/module.

m = InstanceMethods[String]
m.public
...

Just scratching for ideas at the moment. Send them in!!

Gavin
 
D

David A. Black

Hi --

My initial reaction was that it's too much like self. But now that I've given
it some more thought it probably is an excellent choice.

1) It's a pronoun
2) It's very short
3) It has some semantic value, i.e. as in (me)thod
4) It not really used for anything else (AFAIK)

I think your initial reaction was right :) With things like this, I
usually run through in my mind what it would be like to teach it to a
new Rubyist. I think trying to explain "self" and "me" would be
awkward.


David
 
A

Ara.T.Howard

Hmmmm... then we'd have proc, Proc, lambda, block, closure, method, *and*
function :)

touche. i humbly withdraw my nomination. ;-)

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 
T

trans. (T. Onoma)

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

Okay, I see. I did some research to understand. The problem I see with this is
that it might have too large an overhead --in effect creating a binding prior
to every method invocation. Is that so? On the other hand, I see no reason
for 'self' of caller not to be available.

T.
 
T

trans. (T. Onoma)

I think your initial reaction was right :) With things like this, I
usually run through in my mind what it would be like to teach it to a
new Rubyist. I think trying to explain "self" and "me" would be
awkward.

I understand. Yet I can think of worse things to explain, like pg. 216 - 219
of my pickaxe, Variables and Constants ;) Boy, it would be nice if more of
those were "classified" (and I feel likewise about a number of Kernel methods
too).

T.
 
M

Markus

Not seriously floating this (unless everyone loves it) but the
traditional way of referring to the present routine in code reviews (and
even in comments) is "we" as in "we sort the array first, so that when
we look through it we see the likely prospects..."

-- MarkusQ
 
T

trans. (T. Onoma)

Not seriously floating this (unless everyone loves it) but the
traditional way of referring to the present routine in code reviews (and
even in comments) is "we" as in "we sort the array first, so that when
we look through it we see the likely prospects..."

Do we now? ;)

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top