Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to load a ruby file in rubygems?


Asked by Bruce Gutierrez on Dec 11, 2021 Ruby



That’s basically it for what’s in a gem. Drop Ruby code into lib, name a Ruby file the same as your gem (for the gem “freewill” the file should be freewill.rb, see also name your gem) and it’s loadable by RubyGems.
Keeping this in consideration,
Once you’ve required ap, RubyGems automatically places its lib directory on the $LOAD_PATH. That’s basically it for what’s in a gem. Drop Ruby code into lib, name a Ruby file the same as your gem (for the gem “freewill” the file should be freewill.rb, see also name your gem) and it’s loadable by RubyGems.
Accordingly, RubyGems modifies your Ruby load path, which controls how your Ruby code is found by the require statement. When you require a gem, really you’re just placing that gem’s lib directory onto your $LOAD_PATH. Let’s try this out in irb and get some help from the pretty_print library included with Ruby.
In fact,
The gem command allows you to interact with RubyGems. Ruby 1.9 and newer ships with RubyGems built-in but you may need to upgrade for bug fixes or new features. To upgrade RubyGems or install it for the first time (if you need to use Ruby 1.9) visit the download page. If you want to see how to require files from a gem, skip ahead to What is a gem
Just so,
To add the awesome_print directories to the load path, you can require one of its files: Note: For Ruby 1.8 you must require 'rubygems' before requiring any gems. Once you’ve required ap, RubyGems automatically places its lib directory on the $LOAD_PATH.