如何从命令行直接调用ruby函数?从命令行调用ruby函数
想象一下,我想有此脚本test.rb:
class TestClass
def self.test_function(some_var)
puts "I got the following variable: #{some_var}"
end
end
如果这个脚本在命令行(ruby test.rb
)运行,没有任何反应(如预期)。
有没有类似ruby test.rb TestClass.test_function('someTextString')
?我想获得以下输出:I got the following variable: someTextString
。
+1 :)。也。用于方法和变量名称的CamelCase是非Ruby风格的。使用undersore:'test_function','some_var' – fl00r 2012-04-25 13:32:14
@ fl00r好点!我更新了答案。 – Candide 2012-05-02 17:15:22
查看[回复人:@lunero](http://stackoverflow.com/a/37948278/1245614)多个参数 – skitheo 2016-12-14 21:03:05