1

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?

2 Answers 2

3
$ 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/

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

I'm don't want it in irb, I want it in my terminal like in "github.com/defunkt/hub"
Oh, that kind of console. Sunny J. has the answer. What you mean is a "shell command" in this case. "console" usually refers to things like rails console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.