On Wed, 2004-09-08 at 10:16, Florian Weber wrote:
> hi!
> 
> is there a better way to do this:
> 
> options = <<-END_OF_OPTIONS
> 	#{options.inspect}
> END_OF_OPTIONS
> options.gsub!("\\\"", "'")
> 
> module_eval <<-"end_eval", __FILE__, __LINE__
>    def foo
>      some_method_which_expects_a_hash(#{options})
>    end
> end_eval

I'm not exactly sure what you are trying to do.  Do any of these do what
you want?  And by "better" are you meaning faster, easier to maintain,
more robust, or...?


options = eval(options.inspect.gsub(/[\]{3}/,"'"))

or 

options.each_key { |k| options[k].gsub(/[\]{3}/,"'") }

or 

temp = {}
options.each_pair { |k,v| 
    temp[k.gsub(/[\]{3}/,"'")] = v.gsub(/[\]{3}/,"'") 
    }
options = temp


Also, why do you need to jump through hoops to define foo?  Is "options"
going to change later?

-- Markus