<p>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:</p>

<p><code>Object.variable_name= 'new value'</code> </p>

<p>However, after implementing this I found out that many of the variable names have periods (.) in them. I have found this workaround:</p>

<p><code>Object.send('variable.name=', 'new value')</code></p>

<p>However, I am wondering is there a way to escape the period so that I can use</p>

<p><code>Object.variable.name= 'new value'</code></p>

[{'answer_id': 49255, 'author': 'Nick Retallack', 'author_id': 2653, 'author_profile': 'https://Stackoverflow.com/users/2653', 'pm_score': 4, 'selected': True, 'text': '<p>Don\'t do it!</p>\n\n<p>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:</p>\n\n<pre><code>attr_writer :bar\nattr_reader :baz\nattr_accessor :foo\n</code></pre>\n\n<p>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.</p>\n\n<pre><code>class SillySetter\n  def initialize path=nil\n    @path = path\n  end\n\n  def method_missing name,value=nil\n    new_path = @path ? "#{@path}.#{name}" : name\n    if name.to_s[-1] == ?=\n      puts "setting #{new_path} #{value}"\n    else\n      return self.class.new(path=new_path)\n    end\n  end\nend\n\ns = SillySetter.new\ns.foo = 5              # -&gt; setting foo= 5\ns.foo.bar.baz = 4      # -&gt; setting foo.bar.baz= 4\n</code></pre>\n\n<p>I didn\'t want to encourage ruby sillyness, but I just couldn\'t help myself!</p>\n'}, {'answer_id': 49575, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 0, 'selected': False, 'text': "<p>If there's no hope of changing the canonical names, you could alias the getters and setters manually:</p>\n\n<pre><code>def variable_name\n send 'variable.name'\nend\n\ndef variable_name=(value)\n send 'variable.name=', value\nend\n</code></pre>\n"}, {'answer_id': 103920, 'author': 'fatgeekuk', 'author_id': 17518, 'author_profile': 'https://Stackoverflow.com/users/17518', 'pm_score': 1, 'selected': False, 'text': "<p>The only reason I can think of to do this, is if you really REALLY hate the person who is going to be maintaining this code after you.</p>\n\n<p>And I don't mean 'he ran over my dog' hatred. </p>\n\n<p>I mean real steaming pulsing vein in temple hatred.</p>\n\n<p>So, in short, don't. :-)</p>\n"}]
['https://Stackoverflow.com/questions/49252', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5004/']