J
Jeroen Lodewijks
hi,
I am totally new to Ruby and am trying to code a hash of a hash.
Somehow I always get a syntax error, but am unable to resolve it.
This is what I have:
File 1:
class Hashhash
def initialize
@dt = { 2 => {2 => "H", 3 => "C"},
3 => {2 => "H", 9 => "Dh"},
"T" => {2 => "C", 9 => "S"}
}
return @dt
end
end
File 2:
require 'Hashhash'
ah = Hashhash.new
out = ah["T"][9]
p out
I always get this error:
test.rb:5: undefined method `[]' for #<Hashhash:0x2bd2e30>
(NoMethodError)
But when I try to code something in irb it works:
irb(main):006:0* dt = { 2 => {2 => "H", 3 => "C"}}
=> {2=>{2=>"H", 3=>"C"}}
irb(main):007:0> puts dt[2][2]
H
=> nil
What am I doing wrong??
Thanks in advance
I am totally new to Ruby and am trying to code a hash of a hash.
Somehow I always get a syntax error, but am unable to resolve it.
This is what I have:
File 1:
class Hashhash
def initialize
@dt = { 2 => {2 => "H", 3 => "C"},
3 => {2 => "H", 9 => "Dh"},
"T" => {2 => "C", 9 => "S"}
}
return @dt
end
end
File 2:
require 'Hashhash'
ah = Hashhash.new
out = ah["T"][9]
p out
I always get this error:
test.rb:5: undefined method `[]' for #<Hashhash:0x2bd2e30>
(NoMethodError)
But when I try to code something in irb it works:
irb(main):006:0* dt = { 2 => {2 => "H", 3 => "C"}}
=> {2=>{2=>"H", 3=>"C"}}
irb(main):007:0> puts dt[2][2]
H
=> nil
What am I doing wrong??
Thanks in advance