I am trying to understand how to work with a single quote within an eval
such as:
assigned_string = ''
name = "Addy's"
eval("assigned_string='#{name}'")
SyntaxError: (eval):1: syntax error, unexpected tIDENTIFIER, expecting $end
assigned_string='Addy's'
^
Ok, this error makes sense, but when I try to escape the single quote I also
get an error:
eval("assigned_string='#{name.gsub(/'/,"\'")}'")
SyntaxError: (eval):1: syntax error, unexpected tIDENTIFIER, expecting $end
assigned_string='Addy's'
However if I want to just remove the single quote I am fine and get no
error:
eval("assigned_string='#{name.gsub(/'/,"")}'")
Is there a different way to do such an eval? In actuality what I am doing
with this phrase is to assign hash params to the attributes of a class:
eval("background_process_status.#{key.to_s}='#{value}'")
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.