Ruby Command Line LoadError

When I try to include the library in the command line, I get LoadError messages

$ ruby -v ruby 1.8.7 (2012-06-29 patchlevel 370) $ gem list | grep coderay_bash coderay_bash (1.0.2) $ ruby -rcoderay_bash /bin/coderay -v ruby: no such file to load -- coderay_bash (LoadError) $ ruby -rubygems -rcoderay_bash /bin/coderay -v ruby: no such file to load -- coderay_bash (LoadError) 

It works with ruby ​​1.9.2

 $ ruby -v ruby 1.9.2p290 (2011-07-09) $ ruby -rcoderay_bash /bin/coderay -v CodeRay 1.0.7 
+4
source share
1 answer

In Ruby 1.8, anything you want require installed with RubyGems cannot be obtained until you become require 'rubygems' . 1.9 eliminates this requirement.

You have several options for this:

  • Just put require 'rubygems' at the top of the file. This is harmless to 1.9 and probably the easiest thing, because it is in code and no one using your application should remember anything.
  • Change the shebang line to #!/usr/bin/env ruby -rubygems . This tells the Ruby interpreter that it requires rubygems, but allows users to avoid this by sending your file to ruby directly if they are offended by RubyGems for some reason.
  • Always run with ruby and use -rubygems , for example. ruby -rubygems my_app.rb This does not depend on the RubyGems in your code and will work, but you have to remember this every time, which is a little painful.
+2
source

All Articles