J
Jeff Leeman
Is it not possible to pass hashes as command-line arguments to a Ruby
script?
Thanks,
Jeff
script?
Thanks,
Jeff
Jeff said:Is it not possible to pass hashes as command-line arguments to a Ruby
script?
Jeff said:Well, what I'm looking for is to be able run something like:
ruby script/runner "SomeClassName.method_name({:some_key_1 =>
'some_value_1', :some_key_2 => 'some_value_2', :some_key_3 =>
'some_value_3'})"
Sebastian said:Jeff said:Well, what I'm looking for is to be able run something like:
ruby script/runner "SomeClassName.method_name({:some_key_1 =>
'some_value_1', :some_key_2 => 'some_value_2', :some_key_3 =>
'some_value_3'})"
You're perfectly able to run something like that. See:
~> mkdir script
~> cat>script/runner
class SomeClassName
def self.method_name(hash)
p hash
end
end
eval ARGV[0]
~> ruby script/runner "SomeClassName.method_name({:some_key_1
=> 'some_value_1', :some_key_2 => 'some_value_2', :some_key_3
=> 'some_value_3'})"
{:some_key_1=>"some_value_1", :some_key_2=>"some_value_2",
:some_key_3=>"some_value_3"}
HTH,
Sebastian
Jeff said:Which OS are you using?
Also, are you running this from an IRC prompt
or a standard bash shell?
Jeff said:Well, what I'm looking for is to be able run something like:
ruby script/runner "SomeClassName.method_name({:some_key_1 =>
'some_value_1', :some_key_2 => 'some_value_2', :some_key_3 =>
'some_value_3'})"
Joel said:You could just eval ARGV[0] in this case.
$ ruby -e 'p eval(ARGV[0])' '{:foo => :bar}'
{:foo=>:bar}
Jeff said:C:\rails_app>jruby script\runner "SomeClassName.method_name({:some_key_1
=> 'some_value_1', :some_key_2 => 'some_value_2'})"
script\runner:6: (eval):1: , unexpected '=' (SyntaxError)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.