Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对红宝石和宝石制作非常陌生。我制作了一个简单的 gem,它根据输入来抓取一些信息。但是,要使用我的 gem,我需要进入解释器 (irb) 并要求我的 gem,然后使用一些参数调用该方法。
假设 gem 被调用foo。假设该方法被调用print_website(x) # where x is a string。
foo
print_website(x) # where x is a string
我希望能够做类似的事情:
$ foo test.com
它应该自动调用该方法并执行它。
提前致谢!如果我不清楚,请向我澄清!:D
试试看
$ mkdir bin $ touch bin/foo $ chmod a+x bin/foo
编辑bin/foo
#!/usr/bin/env ruby require 'foo' #Anything you want.......
将以下内容添加到 Gemfile
s.executables << 'foo'
推宝石。现在您发布了命令行实用程序
很简单,只需bundle gem mygem -b在创建 gem 时运行。
bundle gem mygem -b