This however would need public/protected/private changed a bit so they will take a Method as their parameter and use its Symbol.
...but Methods don't have Symbols.
why not ? In the Ruby User Guide you can see an example from matz, using the same symbol for a method, a class, and an object
Why don't we just let def return a little struct (or something similar) which contains both the UnboundMethod and the Symbol?
This would allow us to do even more things with it like (example from ruby-talk-posting by Dave Thomas)
externally_typed(String) def get_name
@first + " " + @last
end
or the already mentioned
private def x
do internal stuff
end
Of course private and friends would need to be slightly altered for this:
alias :old_private :private
def private(*args)
if args and args[0] and args[0].is_a? MethodData
old_private shift(args).symbol, *args
else
old_private *args
end
end
I'd argue that UnbondMethod should have an accessor that returns the name as a Symbol.
Well, I was going to post in agreement, but as I sit here thinking about it, I have to ask... does an UnboundMethod really have a name? Isn't it, by definition, unbound to any given name or thing? Or am I misunderstanding what an UnboundMethod really is?
BoundMethod?
[My name is Harald Gutsche from Germany]
just to throw some cents in...
I think, functions really should be objects (because everything should be)
so, this should be possible:
# anonymous function
f = def (x); puts x; end; f(77)
also this:
SomeClass.f = f; x = SomeClass.new; x.f(88)
also
x = SomeClass.new; x.f = f; x.f(88)
a bound method should carry it's (definition) name,
def f; end # bound
differs from
f = def; end # unboundf.name
should give the name
Functions are exactly like blocks but with different scope semantics, they don't have access to lexical variables around them, but blocks have.
So, one could have a function which turns a block into a function:
add = function begin |x,y|; x+y; end
which is equivalent to
add = def (x,y); x+y; end
so,
add = def |x,y|; x+y; end
should also be possible
I come to the conclusion that it should return a Method-object. And Method-Objects should have a to_sym method defined as something which produces an equivalent result as this one, but in a nicer way
class Method
def to_sym
self.to_s[/)#(.*)>$/, 1].intern
end
end
Make def return something useful (dmiceman, 2003-11-28 00:12:24)
i`m also think what _all_ language constructions should return something. not only def, but also class and module.
def should return new Method object.
Re: Make def return something useful (, 2003-05-17 15:27:34)
...but Methods don't have Symbols.
Re: Make def return something useful (, 2003-05-19 03:00:28)
Why not return an UnboundMethod *and* the Symbol? (, 2003-05-26 17:11:00)
This would allow us to do even more things with it like (example from ruby-talk-posting by Dave Thomas)
or the already mentionedOf course private and friends would need to be slightly altered for this:
Well.. (root, 2003-05-29 17:33:06)
Hmmm... (ntalbott, 2003-06-17 21:43:45)
Re: Hmmm... (johnplatte, 2003-06-18 10:26:20)
anonymous function, unbound/bound (, 2003-07-11 12:21:38)
just to throw some cents in...
I think, functions really should be objects (because everything should be)
so, this should be possible:
also this:
alsoa bound method should carry it's (definition) name,
differs from should give the nameFunctions are exactly like blocks but with different scope semantics, they don't have access to lexical variables around them, but blocks have.
So, one could have a function which turns a block into a function:
which is equivalent to
so,
should also be possible
After some thinking... (flgr, 2003-11-15 16:27:24)
I come to the conclusion that it should return a Method-object. And Method-Objects should have a to_sym method defined as something which produces an equivalent result as this one, but in a nicer way
Make def return something useful (dmiceman, 2003-11-28 00:12:24)
def should return new Method object.