Hashes in array?

Is this possible? If so, how......???

Oops I meant sessions

bluengreen wrote:

a = [ { :one => 1 } ]

Hi --

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:

: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.

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

bluengreen пишет:

Oops I meant sessions

bluengreen wrote:
  

Is this possible? If so, how......???
    

Why not ?

session[:blah] = { :apple => 'red' }
session[:blah][:foo] = 'bar'

yeah read my follow up...hash in arrays

it's been a pain....mainly because I don't know Ruby enough ....

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