attr_reader foo
The 'foo' above would evaluate to the contents of the variable 'foo'. So, you have to do this: attr_reader :foo
Because we cannot control how this code evaluated, we must quote 'foo'. This greatly limits what we can express. [:foo, :bar].each do |attribute|
attr_reader attribute
end
You probably wouldn't want do actually do that with attr_reader, but it is just an example.No, it would not be nice. It would be in violation with basic ruby syntax.
If that is the best example you could come up with then I'm glad ruby does not allow whatever it is that you're asking for.
But this isn't about regular Ruby syntax, this is about extending Ruby syntax by embedding new languages within it. A new language may have new evaluation rules. As another user points out, there's a syntax called 'alias' that works similarly to my example, so I disagree that it would be violating anything.
>I'm glad ruby does not allow whatever it is that you're asking for.
I'm essentially asking for macros commonly found in the Lisp family of languages.
That's an unfortunate wart on the language (an inconsistency) and not related to your example at all.
I'm essentially asking for macros commonly found in the Lisp family of languages.
Can you come up with a real-world use case for that?