john_b_andrews
4/7/2005 4:28:00 PM
In the following code example, constructing hash1 works fine,
but constructing hash2 gives me a hash with only one key:
###########################################################
hash1 = {
"key1" => "value1" ,
"key2" => "value2"
}
p hash1
p hash1.keys.length
hash2 = {
"key1" => <<EOF
value1
EOF,
"key2" => <<EOF
value2
EOF
}
p hash2
p hash2.keys.length
########################################################
If I move the comma separating the two key/value pairs
to its own line (so that EOF is recognized properly), I get
a syntax error:
T2.rb:17: syntax error
T2.rb:18: warning: useless use of a literal in void context
T2.rb:18: syntax error
"key2" => <<EOF
^
Is there any way to do this using "here" documents (<<EOF)
and the Hash {} constructor style? I know I can do it by
constructing the hash another way, but...
Thanks,
JA