Ruby on Rails Tuesday, April 30, 2013

While the below code working :-


m = {:a => 2, :b => 3,:c => 44,:g => 14}
a = [:a,:b,:g]
p m.values_at(*[:a,:b,:g]) #=> [2, 3, 14]

why the below not working?

h = {
'arg0' => '126150656000',
'arg1' => 'Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz',
'arg2' => '2790',
'arg3' => '3276320768',
'arg4' => '8467496960',
'arg5' => 'Windows 7',
'arg7' => 'amd64',
'arg6' => '6.1',
'arg8' => '2',
'arg9' => '1920',
'arg10' => '1200',
'arg11' => '32',
}


p ar = h.keys.sort_by{|s| s[3..-1].to_i}
p h.values_at[*ar]
#=>`[]': wrong number of arguments (12 for 1..2) (ArgumentError)

Where did I mistake?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment