For a project I am working on in ruby I am overriding the method_missing method so that I can set variables using a method call like this, similar to setting variables in an ActiveRecord object:
Object.variable_name= 'new value'
However, after implementing this I found out that many of the variable names have periods (.) in them. I have found this workaround:
Object.send('variable.name=', 'new value')
However, I am wondering is there a way to escape the period so that I can use
Object.variable.name= 'new value'
Don’t do it!
Trying to create identifiers that are not valid in your language is not a good idea. If you really want to set variables like that, use attribute macros:
Okay, now that you have been warned, here’s how to do it. Just return another instance of the same class every time you get a regular accessor, and collect the needed information as you go.
I didn’t want to encourage ruby sillyness, but I just couldn’t help myself!