Yep.. Thanks alot. This some pretty neat stuff. :-)
hash = {
"foo" => Proc.new {
x = []
y = []
hash = {
"x" => ["a", "b", "c"].each {|i| x << i},
"y" => ["x", "y", "z"].each {|i| y << i}
}
}.call
}
puts hash['foo']["y"][1]
puts hash['foo']["x"][1]
>ruby test1.rb
y
b
>Exit code: 0
On 8/11/06, Peña, Botp <botp@delmonte-phil.com> wrote:
> fr x1:
> # can you define the value of a hash based on an iteration, or an if
> # statement etc..
>
> if it's code that you want, then Proc can do anything
>
> irb(main):003:0> hash = {"foo" =>Proc.new {1+1 == 3 ? "yes" : "no"}}
> => {"foo"=>#<Proc:0x02b0f124@(irb):3>}
> irb(main):005:0> hash["foo"]
> => #<Proc:0x02b0f124@(irb):3>
> irb(main):006:0> hash["foo"].call
> => "no"
>
> is that what you want?
> kind regards -botp
>
>