这是一个关于包含 .rb 文件的初学者问题。
我想访问在另一个 rb 文件中声明的数组。我的主程序是这样的:
#!/usr/bin/env ruby
load 'price.rb'
[...]
max_price = price[az][type] * 2
[...]
这是 price.rb :
price = {'us-east-1' => {'t1.micro' => 0.02, 'm1.small' => 0.08, 'c1.medium' => 0.165, 'm1.large' => 0.320 },
'us-west-1' => {'t1.micro' => 0.02, 'm1.small' => 0.08, 'c1.medium' => 0.165, 'm1.large' => 0.320 },
'eu-west-1' => {'t1.micro' => 0.02, 'm1.small' => 0.085, 'c1.medium' => 0.186, 'm1.large' => 0.340 }
}
当我运行主脚本时,出现此错误:
Error: undefined local variable or method `price' for main:Object
你怎么看 ?