From: Robert Klemme Date: 2006-08-11T15:10:13+09:00 Subject: Re: Simple question regarding hashes x1 wrote: > Is something like this possible? > > asdf = {"letters" => |||||some code that returns something|||||} > > This is difficult for me to explain being that im not a "programmer" > but.. here's what im trying to do: > > asdf = {"letters" => (if 1+1 == 3; return "yes";else return "no";end)} > ### in hopes that this would set asfd['letters'] equal to "no" > > or.. something like this: > asdf = {"letters" => ["a", "b", "c"].each {|letter| yield letter if > letter != "b"}} > ### in hopes that asdf['letters'] will equal ["a", "b"] > > > i realize, I could do ["a", "b", "c"].delete("b") but my question is > can you define the value of a hash based on an iteration, or an if > statement etc.. > > > Thank you Do you want to use the calculation only once, i.e. on insertion? Then hash = {"foo" => (1+1 == 3 ? "yes" : "no")} hash = {"foo" => if 1+1 == 3 then "yes" else "no" end} robert