Dear All, I have some data in two variables. I can''t merge those data into single variable. For example:- Profile hash contains some 50 key value pair. profile["name"] profile["image"] Post hash also contains some 50 key value pair. Post["comment"] Post["Url"] I want to display 1st record of profile and 1st record of post in same line. Regards, Priya -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 December 2010 09:57, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Dear All, > > I have some data in two variables. I can''t merge those data into single > variable. > > For example:- > > Profile hash contains some 50 key value pair. > profile["name"] > profile["image"] > > Post hash also contains some 50 key value pair. > Post["comment"] > Post["Url"] > > I want to display 1st record of profile and 1st record of post in same > line.What do you mean by 1st record of profile? Profile is a hash so does not have records. Colin> > Regards, > Priya > > -- > 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #967377:> On 9 December 2010 09:57, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> Post hash also contains some 50 key value pair. >> Post["comment"] >> Post["Url"] >> >> I want to display 1st record of profile and 1st record of post in same >> line. > > What do you mean by 1st record of profile? Profile is a hash so does > not have records. > > Colin1st record of profile means, 1st key value pair. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 December 2010 10:20, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #967377: >> On 9 December 2010 09:57, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >>> Post hash also contains some 50 key value pair. >>> Post["comment"] >>> Post["Url"] >>> >>> I want to display 1st record of profile and 1st record of post in same >>> line. >> >> What do you mean by 1st record of profile? Profile is a hash so does >> not have records. >> >> Colin > > 1st record of profile means, 1st key value pair.I believe hashes are not ordered so there is no such thing as the 1st key. You can use profile.each_pair to iterate through the keys, but which one you get first is not guaranteed. Colin Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #967382:> On 9 December 2010 10:20, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> What do you mean by 1st record of profile? Profile is a hash so does >>> not have records. >>> >>> Colin >> >> 1st record of profile means, 1st key value pair. > > I believe hashes are not ordered so there is no such thing as the 1st > key.In Ruby 1.8, hashes are not ordered. In Ruby 1.9, they are ordered. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 December 2010 16:30, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #967382: >> On 9 December 2010 10:20, Priya Baskar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>>> What do you mean by 1st record of profile? Profile is a hash so does >>>> not have records. >>>> >>>> Colin >>> >>> 1st record of profile means, 1st key value pair. >> >> I believe hashes are not ordered so there is no such thing as the 1st >> key. > > In Ruby 1.8, hashes are not ordered. In Ruby 1.9, they are ordered.Yes of course, I had forgotten that. So to answer the OPs question, how to show the first pair from each hash together, he could do <%= profile.keys[0] profile[ profile.keys[0] ] post.keys[0] post[ post.keys[0] ] %> obviously with some tidying up. Though I am not sure that is actually what he wants to do. Also if he is not using ruby 1.9 he may not get the results he expects. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Guys, Actually there is some attributes common to both the hashes, using that common attribute, i''m displaying the results. It works for me. Thank you very much for your help. Thanks & Regards, Priya -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.