I'm working through Zed Shaw's Learn Ruby The Hard Way and I'm having an issue including a module in IRB. In exercise 25, we define a new module Ex25, require it in IRB, and then can use its various methods through the namespace of that module, e.g. Ex25.break_words(sentence). In the Extra Credit, it's stated that typing include Ex25 will basically add the methods from the module into the current "space" (not sure what to call it) and you can then call them without explicitly referring to the module, e.g. break_words(sentence). When I do this, however, I'm getting an "undefined method" error. Any help / explanation would be greatly appreciated, thanks!
Ruby Include Module in IRB
3.3k Views Asked by orenyk At
1
There are 1 best solutions below
Related Questions in RUBY
- Best way to make an HABTM association via console
- undefined method `namespace' for main:Object (NoMethodError) - active record / rakefile
- Ruby destroy is not working? Or objects still present?
- Trying to set the value of an input with mechanize
- How to split the logic in a ruby game
- How can I monitor an endpoint's status with Ruby?
- Why can a private class method be explicitly invoked in Ruby?
- Rails - Ajax do not work properly on production server
- syntax error, unexpected kEND
- Carrierwave file upload with different file types
- b.javascript_dialog().exists? is not working for me in WATIR 4.0.2
- Combine two arrays of hashes
- Building a simple calculator form in Rails 4
- How do I update create route from rails 3 to 4
- Comparison of Fixnum with nil failed - palindrome program Ruby
Related Questions in IRB
- Why might interactive ruby stop showing results?
- Can't start IRB intermittently because of activerecord error
- Strange behavior with '_' (underscore) in Ruby
- Testing with Joda DateTime in irb
- "-" == "-" returns false.. Why?
- PRY or IRB - reload class and forget deleted functionality
- Ruby: What happens to a the value of a statement after execution?
- Difference in output between Ruby versions when running script
- Execute a jar in separate console(command prompt/terminal) from another java application
- IRB - unfinished expression at operator's symbol?
- How do you disable awesome_print once enabled in IRB or rails console?
- How make `reverse-i-search` history use fzf in irb or pry console
- IRB - NameError: undefined local variable or method for main:Object
- print random unicode card in console
- Why isn't current directory on my Ruby path?
Related Questions in LEARN-RUBY-THE-HARD-WAY
- Not displaying it's corresponding values with it's key for Hash
- Push an array into another array with Ruby, and return square brackets
- "Undefined method 'close'" when trying to close a file in Ruby
- load 'file.rb' versus require 'Module' in Ruby
- Ruby gets.chomp and $stdin.gets.chomp difference
- gets.chomp inside a function in ruby
- Cannot install Ruby 1.9.2 using rvm on MAC osx
- Stuck on Zed Shaw's ruby exercise
- Ruby Include Module in IRB
- How do I create a paragraph in Ruby?
- Ruby Basics: Pop Method in Array
- Learn Ruby the hard way Ex 41. - what's with the multi-line string?
- Ruby the hard way example 39
- Ruby(HardWay(ex9)) << uninitialized constant PARAGRAPH
- Learn Ruby the Hard Way ex39: return -1, key, default
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
That's an error in the book. The methods in
Ex25are class methods.includeadds instance methods to the "current space." Removeselffrom the method definitions and it'll work:If you're curious, here's some more detail about what's going on: The place where the methods are included—the "current space"—is the Object class:
All Object instances gain the included methods ...
... and the top-level is just an Object instance:
But wait. If the top-level is an Object instance, why does it respond to
include? Isn'tincludean instance method ofModule(and its subclass,Class)? The answer is that the top-level has a singleton method ...... which we can assume forwards to the Object class.