Here is class foo
class Foo
def initialize(&block)
instance_eval(&block) if block
end
def bar(hash)
@bar = hash
end
end
why is this syntax error
foo = Foo.new do
bar {:param1=>'value1', :param2=>"value2"}
end
the syntax error this gives me is
SyntaxError: unexpected ',', expecting '}'
bar {:param1=>'value1',:param2=>'value2'} whats the proper way to use hash inside instance_eval like the example above. What i really need is to pass in hash to a method inside instance_eval
bar({:param1=>'value1', :param2=>"value2"}). As it is,{:param1=>'value1', :param2=>"value2"}is treated as block rather than an argument.bar :param1=>'value1', :param2=>"value2"orbar param1: 'value1', param2: "value2"(or the same with parentheses).