故事
你好,我决定试试鲁比。我从Ruby官方网站获得了一个关于如何在10分钟内学习Ruby主要概念的链接。
Link here
本教程直截了当,易于理解。我明白代码应该做什么,但它并没有按预期工作。
信息:
-
不,我运行控制台时没有收到任何错误。
-
我在Mac上使用Aptana控制台
-
我的
ruby--版本:
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
代码:
#!/usr/bin/env ruby
class Test
def initialize app_map
@app_map = app_map
end
def run file_name
application = select_app file_name
system "#{application} #{file_name}"
end
def select_app file_name
ftype = file_type file_name
@app_map[ ftype ]
end
def file_type file_name
File.extname( file_name ).gsub(/^\./, '').downcase
end
end
def help
print "
You must pass in the path to the file to launch.
Usage: #{__FILE__} target_file
"
end
if ARGV.empty?
help
exit
end
app_map = {
'html' => 'firefox',
'rb' => 'gvim'
}
test = Test.new app_map
target = ARGV.join ' '
test.run target
它可能不明显,但您可以在代码框中向下滚动。
那么这应该做什么呢?
$ ruby test.rb test.rb
要运行它,需要添加1个参数。它可能是
.rb或.html
(我都试过)。如果是
.html文件
程序应该在其中打开的文件
萤火虫
,如果是
.rb文件
它应该用
文字编辑器
.
问题:
为什么它不起作用?我做错了什么?谢谢