7

I am currently working on developing a gem and I would like to be able to run that gem from command line and point it to my local source. Previously I've done this in rails by specifying the path in the gem file but now I would like to run the gem on a non rails app. So I would like to know how to call the gem from command line and specify that I want to use the source code in a certain directory.

For example can I cd into the directory that I want to run it on and do something like: ruby my_gem --path=~/code/mygem

Also do I have to build them gem or can I run it from source without building it?

2
  • Your requirement is not clear. You are trying run your gem by specifying path. You can use irb to (not sure as requirement is not clear). Can you please elaborate? Commented Mar 16, 2015 at 15:04
  • Yes sorry, I would like execute a development version of the gem (rubycritic) from the root directory of another ruby project. So I would like to cd into ~/code/another_ruby_project and then run my version of rubycritic on the code in that directory. For reference: github.com/whitesmith/rubycritic Commented Mar 16, 2015 at 15:29

1 Answer 1

10

From the root directory of your gem, try this to execute lib/MyGem.rb:

ruby -Ilib lib/MyGem.rb

or test your gem interactive:

irb -Ilib
> require 'mygem'
true
Sign up to request clarification or add additional context in comments.

Comments

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.