I am using Ruby on Rails 3 and I would like to implement something that works like params.
Normally in a RoR application you can use params[:name] to access the ‘name’ value. In my case I need to have “something” like my_function_params[:name] that works like params[:name].
I don’t need all features of the params method because I will use that like a variable statement and only internally my methods. This is because I would like to work on that instead of local variables.
Example:
# What I would like to do
my_function_params[:name] = "Test name"
if my_function_params[:name] == "Test name"
...
end
instead of
# What I would not do
name = "Test name" == "Test name"
if name
...
end
How can I do that?
You can use a Hash:
my_function_params = {name: "Test name"} my_function_params[:attribute] = "Another attribute" if my_function_params[:name] == "Test name" puts "hi" end => hi