Ruby - escape a number leading variable name -


I'm already using () to insert a table that exists, but some table fields and With variable number starting at present, I am currently receiving a syntax error "unexpected tIDENTIFIER" in Ruby when I try to do something like the following -

  foo.each do | X | Object. Create (3pm: x.3pm, 3pa: x.3pa) and  

If I call it '3pm' = & gt; X.3pm , it gives me a syntax error on the x.3pm section.

How can I survive to succeed it?

The problem is that 3pm is not in Ruby, in Ruby, : Name With the syntax and the name of the method, the symbol symbols should be both valid identifiers.

In the case of the key, instead of using the symbol literals for the syntax, or : 'name' as you've searched for:

 < Code> foo.each do | X | Object. Create (= '3pm' =>; x.3pm, '3pa' => x.3pa) end  

Unfortunately, this still is the problem of 3pm Leave and 3pa are not valid method names, generally, because these are not the names of valid methods, so they can be used in the first place on the x Could not even use However, in this case, the x is probably using either the utility of a method called Ruby or 3pm or using its features (even if it is normally Not a valid method, in the name Ruby).

Thankfully, we can use this method to call:

  foo.each do | X | Object.create (: '3pm' => gtpublic_send ('3pm') ,: '3pa' => x.public_send (: '3pa'))  
< P> This should solve your problem.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -