7stud -- wrote:
> 
> Here's where fetch would make a difference:
> 

Or in this case:

Frederick Cheung wrote:
> or do you sometimes explicitly store nil in
> the session (and want that to be distinct from
> the value not being there at all) ?) ?

h = {"red" => nil, "blue" => true, "yellow" => nil}

puts h.fetch("green", "don't carry that color")


This is where it gets tricky and you have to be a little careful:

h = {"red" => nil, "blue" => true, "yellow" => nil}
result = h.fetch("blue", "don't carry that color")

if result == "dont't cary that color"
  puts "Sorry"
elsif result
  puts "Available"
else
  puts "Out of stock"
end


--output:--
Available

-- 
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to