This is a legacy RCR. If this is your RCR, please resubmit it using the new format and process.
I'd really like def to return something useful like the Symbol of the newly created Method. -- This would make it possible to do something like this:
private def x do internal stuff end
You might even want to return the created Method itself instead of its Symbol. This however would need public/protected/private changed a bit so they will take a Method as their parameter and use its 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
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 # bounddiffers from
f = def; end # unboundf.nameshould 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)
Back to RCRchive.
RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog
...but Methods don't have Symbols.