制作红宝石响应终端命令 [英] Making ruby gems respond to terminal commands
问题描述
我对红宝石以及宝石制作极其新颖。我做了一个简单的宝石,根据输入信息对一些信息进行网络扫描。
然而,要使用我的宝石,我需要进入解释器(irb)并需要我的宝石,然后用一些参数调用该方法。
假设宝石被称为 foo
。
假设这个方法叫做 print_website(x)#其中x是一个字符串
。
我想能够做这样的事情:
$ foo test.com
,它应该自动调用该方法并执行它。
预先感谢!如果我不清楚,请问我澄清! :D
试试看
$ mkdir bin
$ touch bin / foo
$ chmod a + x bin / foo
编辑 bin / foo
#!/ usr / bin / env ruby
需要'foo'
#你想要的东西.......
将以下内容添加到Gemfile中
s可执行文件<< 'foo'
推宝石。现在你发布了命令行工具
I am extremely new to ruby as well as gem making. I made a simple gem that webscrapes some information depending on the input. However, to use my gem I need to go into the interpreter (irb) and require my gem and then call the method with some parameters.
Suppose the gem is called foo
.
Suppose the method is called print_website(x) # where x is a string
.
I want to be able to do something like:
$ foo test.com
and it should automatically call the method and execute it.
Thanks in advance! Please ask me for clarification if i was unclear! :D
Try it
$ mkdir bin
$ touch bin/foo
$ chmod a+x bin/foo
Edit bin/foo
#!/usr/bin/env ruby
require 'foo'
#Anything you want.......
Add following to Gemfile
s.executables << 'foo'
Push gem. Now you published command line utility
这篇关于制作红宝石响应终端命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!