On Nov 29, 2007 12:09 PM, blinking bear
<blinkingbear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hey - this is pretty ugly and probably not even considered Metaprogramming,
> but have a look/laugh and please suggest a more elegant way:
>
> Basically, I just want to loop through an array of variables to look for in
> the params hash and set them to instance variables with the same name or
set
> them to '''' if non-existant in the hash:
>
> [:criteria, :sort_by, :ord].each { |key| eval("@#{key} =
params[:#{key}] ||
> ''''") }
>
> all this does is just evaluate the following lines:
>
> @criteria = params[:criteria]
> @sort_by = params[:sort_by]
I''m not sure what this is buying you.
You might consider using Object#instance_variable_set instead of eval.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---