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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
p h.values_at[*ar] should be p h.values_at(*ar) On Wed, May 1, 2013 at 12:50 PM, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jim ruther Nill wrote in post #1107440:> p h.values_at[*ar] > > should be > > p h.values_at(*ar) > > > On Wed, May 1, 2013 at 12:50 PM, Love U Ruby <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> ''arg0'' => ''126150656000'', >> ''arg11'' => ''32'', >> Posted via http://www.ruby-forum.com/. >> > --Thanks! It was a typo. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.