D
Dmitry Perfilyev
Hi, I have next script:
t.rb:
===========================
class TestStr < String
attr_accessor :dupstr
def initialize ( str )
@dupstr = str
super(str)
end
end
ts=TestStr.new("aaa")
puts ts.dupstr
h=Hash.new()
h[ts]=true
puts h.keys.first.class
puts h.keys.first
puts h.keys.first.dupstr
===========================
run it:
$ ruby t.rb
aaa
TestStr
aaa
nil
$
The question is - why there is 'nil' in the last line instead of "aaa" ?
t.rb:
===========================
class TestStr < String
attr_accessor :dupstr
def initialize ( str )
@dupstr = str
super(str)
end
end
ts=TestStr.new("aaa")
puts ts.dupstr
h=Hash.new()
h[ts]=true
puts h.keys.first.class
puts h.keys.first
puts h.keys.first.dupstr
===========================
run it:
$ ruby t.rb
aaa
TestStr
aaa
nil
$
The question is - why there is 'nil' in the last line instead of "aaa" ?