Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding and requiring a gem
    primarykey
    data
    text
    <p>I built a gem called prawn_charts and can successfully require the module that wraps all the classes (the classes are all in different files) and the classes from the root directory of the project with this command in irb:</p> <pre><code>require "./lib/prawn_charts.rb" </code></pre> <p>However, when I create the gem with <code>$ rake build</code> and <code>$ rake install</code>, cd to my home directory, and require the gem in irb, I can only load the wrapper module and not any of the individual classes:</p> <pre><code>~ $ irb &gt;&gt; require 'prawn_charts' =&gt; true &gt;&gt; PrawnCharts # this works =&gt; PrawnCharts &gt;&gt; PrawnCharts::YLabelsDataCollector # don't know why this causes an error NameError: uninitialized constant PrawnCharts::YLabelsDataCollector </code></pre> <p>Here is what the <code>lib/prawn_charts.rb</code> file looks like:</p> <pre><code>require 'prawn' require_relative "./prawn_charts/version" module PrawnCharts end # this loads PrawnCharts::YLabelsDataCollector Dir["./lib/data_collectors/**/*.rb"].each {|file| require file } Dir["./lib/renderers/**/*.rb"].each {|file| require file } </code></pre> <p>I also have this line in the gemspec file:</p> <pre><code>gem.files = `git ls-files`.split($/) </code></pre> <p>EDIT:</p> <p>This is what I should have had in <code>lib/prawn_charts.rb</code>:</p> <pre><code>lib_path = File.expand_path(File.dirname(__FILE__)) Dir["#{lib_path}/prawn_charts/data_collectors/**/*.rb"].each {|file| require file } Dir["#{lib_path}/prawn_charts/renderers/**/*.rb"].each {|file| require file } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload