D
Donglai Gong
I'm having trouble accessing instance variables directly. What's wrong
with this...
class Level1
def initialize
@var1='var1 set.'
end
def printvar1
@var1
end
end
l1=Level1.new
print l1.printvar1, "\n"
print l1.var1
I get the following output:
% ruby test.rb
var1 set.
test.rb:13: undefined method `var1' for #<Level1:0x23d5e8 @var1="var1
set."> (NoMethodError)
I'm running version 1.8.0 preview3 on OS X.
Donglai
with this...
class Level1
def initialize
@var1='var1 set.'
end
def printvar1
@var1
end
end
l1=Level1.new
print l1.printvar1, "\n"
print l1.var1
I get the following output:
% ruby test.rb
var1 set.
test.rb:13: undefined method `var1' for #<Level1:0x23d5e8 @var1="var1
set."> (NoMethodError)
I'm running version 1.8.0 preview3 on OS X.
Donglai