HI,
How do I convert a string value to a variable name? To get the value of
the variable.
Is the following technique good design?
I have an app that needs to create urls in a bunch of different
formats. Below is a simplified example.
http://www.site1.com?firstname=Wayne&lastname=Gretzky
http://www.site2.com?fname=Wayne&lname=Gretzky
In my code, I''ve have variables first_name and last_name.
So I put the mappings into a YAML file.
-----
name: site1
base_url: http://www.site1.com?
params:
firstname: first_name
lastname: last_name
name: site2
base_url: http://www.site2.com?
params:
fname: first_name
lname: last_name
------
Then my code:
------------
first_name = "Wayne"
last_name = "Gretzky"
sites_config_file = open(''config/sites.yaml'').read
@sites = YAML.load(sites_config_file)
url = @sites["base_url"]
@sites["site1"]["params"].each do |key,value|
url = url + "&" + key +"="+
eval("#{value}") #HELP HERE
end
puts url;
-----------
How do I get ''value'' to do what I want?
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---