Is this possible? If so, how......??? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Oops I meant sessions bluengreen wrote:> Is this possible? If so, how......???--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org
2006-Sep-27 23:14 UTC
Re: Hashes in array?
array = [ {:key1 => "value1"}, {:key2 =>"value2"} ] to retrieve them you can do something like this: array.each do |hash| hash.each do |key, value| puts key puts value end end -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
a = [ { :one => 1 } ] On 9/28/06, bluengreen <pnovess-ee4meeAH724@public.gmane.org> wrote:> > > Is this possible? If so, how......??? > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi -- On Wed, 27 Sep 2006, bluengreen wrote:> > Is this possible? If so, how......???[ { 1 => 2, 3 => 4 }, { "apple" => "red", "banana" => "yellow" } ] David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
>> a = Array.new=> []>> h1 = Hash.new=> {}>> h2 = Hash.new=> {}>> h3 = Hash.new=> {}>> h1[:stuff] = ''marshmallows''=> "marshmallows">> h2[:stuff] = ''graham crackers''=> "graham crackers">> h3[:stuff] = ''hershey bar''=> "hershey bar">> a << h1=> [{:stuff=>"marshmallows"}]>> a << h2=> [{:stuff=>"marshmallows"}, {:stuff=>"grahm crackers"}]>> a << h3=> [{:stuff=>"marshmallows"}, {:stuff=>"grahm crackers"}, {:stuff=>"hershey bar"}] bluengreen wrote:> Is this possible? If so, how......??? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Guest wrote:> array = [ {:key1 => "value1"}, {:key2 =>"value2"} ] > > > to retrieve them you can do something like this: > > array.each do |hash| > hash.each do |key, value| > puts key > puts value > end > endWhat''s the advantage of using :key as opposed to "key"? I''ve seen it advertised as a ''best practice'' on the Rails Wiki, but it didn''t go into the rationale. Thanks, Nelson -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
:key is a Symbol literal which is always the same object in memory. "key" is a String literal which will create a new object every time you say "key". So, there are performance gains, but more important for me are the semantics of a symbol (think of it like an identifier or a name) and the simple fact that you type and look at less code. Symbols are somewhat tricky to really understand, but I think some of the details are no important once you get used to common usage. They will eventually be a type of String with Ruby 2, but for now, though they seem similar, :key.is_a?(String) returns a most certain false. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks for all the reply''s. Unfortunately i was leaving work when I wrote the thread and I was a little brain dead from trying to solve a problem. I meant to say into sessions not arrays. I''m trying to save hashes into the session and I keep getting 500 errors and TypeErrors. I''m trying to connect to a LDAP directory and save the entry from a search into session for caching from page to page with looking it up again. This is how the applications we have at my work have been written and I want to follow the same methodology. But I keep getting the errors. I know it''s probably related to the object/hash being passed can not be marshaled. However, my Ruby skills are weak at best. So that doesn''t mean squat to me. I pass it to a temp var, I''ve used to_s and that works but I can''t get me stuff back out like I want. It''s just one big string. I pass the hash using to_hash and it gives the same errors as if I passed the object directly. I dunno. Do you guys know? thanks, phill On Sep 27, 2006, at 6:01 PM, Seth Thomas Rasmussen wrote:> > :key is a Symbol literal which is always the same object in memory. > "key" is a String literal which will create a new object every time > you > say "key". So, there are performance gains, but more important for me > are the semantics of a symbol (think of it like an identifier or a > name) and the simple fact that you type and look at less code. > > Symbols are somewhat tricky to really understand, but I think some of > the details are no important once you get used to common usage. They > will eventually be a type of String with Ruby 2, but for now, though > they seem similar, :key.is_a?(String) returns a most certain false. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
bluengreen ïèøåò:> Oops I meant sessions > > bluengreen wrote: > >> Is this possible? If so, how......??? >>Why not ? session[:blah] = { :apple => ''red'' } session[:blah][:foo] = ''bar'' --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
yeah read my follow up...hash in arrays it''s been a pain....mainly because I don''t know Ruby enough .... On Sep 27, 2006, at 7:27 PM, Maxim Kulkin wrote:> > bluengreen ïèøåò: >> Oops I meant sessions >> >> bluengreen wrote: >> >>> Is this possible? If so, how......??? >>> > Why not ? > > session[:blah] = { :apple => ''red'' } > session[:blah][:foo] = ''bar'' > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
you can always examine the contents of the hash in the development error screen and see the hash arrays (key => ''value'') and see what you need to see. or create a simple view template that has <%= debug session %> which will display your session hash in nice formed statements Craig On Wed, 2006-09-27 at 20:09 -0600, phillip novess wrote:> yeah read my follow up...hash in arrays > > it''s been a pain....mainly because I don''t know Ruby enough .... > > On Sep 27, 2006, at 7:27 PM, Maxim Kulkin wrote: > > > > > bluengreen ïèøåò: > >> Oops I meant sessions > >> > >> bluengreen wrote: > >> > >>> Is this possible? If so, how......??? > >>> > > Why not ? > > > > session[:blah] = { :apple => ''red'' } > > session[:blah][:foo] = ''bar'' > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---