我对ruby非常陌生。我对着在得到变量值self.method
在ruby脚本self.method中访问变量
我的Ruby类/脚本看起来像这样的问题:
class A1
def initialize
@myUtil = MyUtil.new log
@test_hash = @myUtil.loadPropertiesFile(File.dirname(__FILE__) + '/my-tests.properties')
end
def self.testCases
tests = {}
@test_hash.each do |k, v|
puts "#{k}"
end
tests
end
def launch test, testbed, h = {}
@test_hash.each do |k, v|
puts "#{k}"
end
end
end
我能够在@test_hash
在启动方法来打印值,但不是在self.testCases
。我犯了什么错误?
你的代码看起来过于复杂。它应该做什么?或者你只是想弄清楚Ruby中的类是如何工作的? – Stefan
看起来像某人在Perl中完成了太多时间。注意像'$ test_hash'这样的全局变量,并且如果你确实声明了它们,则一致地引用它们。这里没有'$'和'@'切换。 – tadman