From: Dave Thomas Date: 2001-05-21T05:05:27+09:00 Subject: [ruby-talk:15434] A proto-RCR: making def and class rvalues Currently, method and class definitions return values, but: 1. It's hard to use these values, as the syntax doesn't allow a method or class definition as an rvalue (so you have to get to them via 'eval'), and 2. The value of these statements isn't too useful. Method definitions return 'nil', and class definitions return the value of the last executed statement in the definition. I'm wondering about the following set of changes: 1. Allow class and method definitions to appear as rvalues 2. Have class definitions always return the newly defined class. 3. Have method definitions return an UnboundMethod object corresponding to the method just defined. 4. Add methods to UnboundMethod to return the name and name as symbol of the method. 5. Alter the functions and statements that currently accept a method name or symbol to also accept an UnboundMethod object. The motivation for all this is that it would make programming various extensions in the Ruby language far more natural. For example, there was recently a thread on synchronized methods. You could write something like: class Rubble def fred #... end synchronized :fred end Say instead that 'def' returned the method object, and you could use a def as an rvalue (say as the parameter to a method). Then you could write class Rubble synchronized def fred #... end end The method gets defined, the UnmoundMethod object gets passed to the method 'synchronized' which then does its magical wrapping. You could also use this at the class level: synchronized class Rubble # ... singleton class Bedrock persistent class Quarry and so on. Does this have merit? Are there any gotchas I'm missing? Dave