I’m learning ruby dev coming from java and I dont understand why im getting below error. @test is a class variable so I should be able to output it ?
C:/Projects/RubyPlayground/Tester.rb:6:in `test': wrong number of arguments (ArgumentError)
from C:/Projects/RubyPlayground/Tester.rb:6:in `testMethod'
from C:/Projects/RubyPlayground/Tester.rb:10
source:
class Tester
@test = "here"
def testMethod()
puts test
end
s = Tester.new()
s.testMethod()
end
In this case @test became class instance variable and is associated with class object (not with class instance!). If you want @test behave like a java field, you have to use ‘initialize’ method: