On 20/10/11 09:38, Kassym Dorsel wrote:
> That could work. Just one last thing to solve.
>
> assignments = {:name1=>"arr.grep(/Input:.*/)[0][6..-1]"}
>
> assignments.each_pair {|k,v| hs[k] = how do I call this command
> associated with :name1}
>
>   .method(:method).call(arguments) and .send("method") only seem to work
> for single methods and  not combined ones like the example above.
>
Well, you can do this, but remember you have to deal with exceptions 
thrown in your proc.

ruby-1.9.2-p290 :001 > hs = {}
  => {}
ruby-1.9.2-p290 :002 > target = []
  => []
ruby-1.9.2-p290 :003 > assignments = {:name1=>Proc.new {|arr| foo = 
arr.grep(/Input:.*/)[0]; foo && foo[6..-1] || nil}}
  => {:name1=>#<Proc:0x000000009c72a0@(irb):3>}
ruby-1.9.2-p290 :004 > assignments.each_pair {|k,v| hs[k] = v.call(target)}
  => {:name1=>#<Proc:0x000000009c72a0@(irb):3>}
ruby-1.9.2-p290 :005 > hs
  => {:name1=>nil}

The proc in assignments could be something like this if you didn't want 
the foo (you can use tap or something to debug inside the proc if needs be)

ruby-1.9.2-p290 :006 > assignments = {:name1=>Proc.new {|arr| 
arr.grep(/Input:.*/)[0][6..-1] rescue nil}}
=> {:name1=>#<Proc:0x00000000872f58@(irb):6>}
ruby-1.9.2-p290 :007 > assignments.each_pair {|k,v| hs[k] = v.call(target)}
  => {:name1=>#<Proc:0x00000000872f58@(irb):6>}
ruby-1.9.2-p290 :008 > hs
  => {:name1=>nil}

Does that help?

Sam