0

When I run a ruby program from the command line, I have to add "ruby" at the beginning of the command (ex. 'ruby hangman.rb'). My question is, how do I make a command line program without having to use 'ruby' in front to run the program. I know this has to be possible because RoR is written in ruby and you don't have to run "ruby rails [command]", you just run "rails". Any Ideas?

4
  • 1
    If you are on windows, you may want to compile ruby. stackoverflow.com/questions/9998819/… Commented Jan 21, 2018 at 21:29
  • 1
    This is documented heavily. You'll want to look up discussions on bin — RubyGems has a nice guide on making an executable, guides.rubygems.org/make-your-own-gem/#adding-an-executable Commented Jan 21, 2018 at 21:30
  • Rails is a gem. Gems are generally run from somewhere in your PATH. See also gem env. Commented Jan 21, 2018 at 22:31
  • It would appear I have some research to do. Thanks! Commented Jan 21, 2018 at 22:55

1 Answer 1

1

Best option would be to bundle it as a Gem - this allows to define an executable.

Another a bit "hacky" option would be to create a hangman.bat file that would just call ruby hangman.rb

Note that both cases would still require ruby to be installed on any target computer.

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.