Reputation: 7742
I created a gem with jeweler and I want a command hat
to call a specific function in my gem.
In Python I can put this
entry_points="""
[console_scripts]
hat = hat:hat
"""
in setup.py
and it works, but how is it done in ruby?
Upvotes: 1
Views: 258
Reputation: 6123
$ 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'
As per:
Making ruby gems respond to terminal commands
There is also:
http://visionmedia.github.com/commander/
Upvotes: 3
Reputation: 211540
For the console, you can add things to your .irbrc
file just as you would in Python.
Within the context of the irb
console, though, methods must be defined in the main
namespace. Obviously you want to be careful about what you add here since it can cause confusion if you start to spike in a large number of these with arbitrary names.
Upvotes: 0