From: "Jesús Gabriel y Galán" Date: 2009-10-27T00:57:29+09:00 Subject: Re: Setting instance variables from hash parameters (with defaults) On Mon, Oct 26, 2009 at 4:42 PM, Leslie Viljoen wrote: > I see this is a shorter way: > > module Defaulting >        def set_params(defs, params) >                defs.merge(params).each {|name, val| eval "@#{name} = val"} >        end > end > > ..still, any way to get rid of that eval? One issue with this approach is that with params you can get arbitrary instance variables injected, while with the other approach you were restricting to the ones you had in defaults. This might be a problem or not... To get rid of the eval, use instance_variable_set. Jesus.