Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fix example for 1.9 (current directory isn't in $LOAD_PATH) #6

Merged
merged 1 commit into from almost 3 years ago

2 participants

Gabriel Horner Gregory Brown
Gabriel Horner
Collaborator

Fix example for 1.9 (current directory isn't in $LOAD_PATH) and be more clear about the $LOAD_PATH antipattern

Gregory Brown sandal merged commit 2424344 into from June 20, 2011
Gregory Brown sandal closed this June 20, 2011
Gregory Brown
Collaborator
sandal commented June 20, 2011

Thanks @cldwalker!

Gabriel Horner
Collaborator

np
Do you want a section in this guide about adding a version to a gem? Too often I see gems with no VERSION constant and strange setups involving VERSION files which aren't under lib/GEM_NAME/. @qrush I would need to add a version.rb to hola

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jun 20, 2011
Gabriel Horner Fix example for 1.9 (current directory isn't in $LOAD_PATh) and be mo…
…re clear about the $LOAD_PATH antipattern
d294dfa
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 5 additions and 9 deletions. Show diff stats Hide diff stats

  1. 14  make-your-own-gem.md
14  make-your-own-gem.md
Source Rendered
@@ -205,21 +205,17 @@ But now our `hola.rb` file has some code to load the `Translator`:
205 205
 
206 206
     require 'hola/translator'
207 207
 
208  
-Let's try this out. First, jump into the `lib` directory, then fire up `irb`!
  208
+Let's try this out. First, fire up `irb`!
209 209
 
210  
-    % cd lib
211  
-
212  
-    % irb -rhola
  210
+    % irb -Ilib -rhola
213 211
     irb(main):001:0> Hola.hi(:english)
214 212
     => "hello world"
215 213
     irb(main):002:0> Hola.hi(:spanish)
216 214
     => "hola mundo"
217 215
 
218  
-Why did we jump into `lib`? Well, by default Ruby adds the current directory
219  
-to your `$LOAD_PATH`. Since we didn't load RubyGems for that last `irb`
220  
-session, we have to rely on only Ruby's `require` to figure out where files
221  
-are. We could have appended the `lib` directory onto the `$LOAD_PATH` array,
222  
-but that's considered a bad pattern for gems. There's many more anti-patterns
  216
+Why did we specify `-Ilib`? Well, in order to use the local version of our gem
  217
+we need to add to the `$LOAD_PATH` with `-I`. We could have done this inside of
  218
+our gem but that's considered a bad pattern for gems. There's many more anti-patterns
223 219
 (and good patterns!) for gems, explained in [this guide](/patterns).
224 220
 
225 221
 If you've added more files to your gem, make sure to remember to add them to
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.