Sometimes Modules can be elusive in their ability. The following script can print a Modules name and methods as a hash for inspection. # ~/gem_reader.rb meths = Dir[’their_gem.rb’].each do |f| name = nil file = file.gsub(/module (\w+)\n/) { name = $1 } meths[name] = file.gsub(/def (\w+)\n/) { meths[name] << $1 } end p meths   # ~/their_gem.rb module Test def testing end end ➜ Desktop ruby file_read.rb {“Test”=>[“testing”]} :)

Helpers in Rails are not my favorite way of interpolating code in the MVC framework, and looking at this example we can see a way to create a text helper which can be used in any model of our Rails application. Let’s use a school example in the following. 1) Create a module with our text helper # app/models/concerns/text_converter.rb module TextConverter def determine_tagline if category.downcase(/science/).any? "Doing great things with Science" elsif category.downcase(/art/).any? "Tell history through a brush" else nil end end end 2) Include the module in a model # app/models/course.rb class Course include TextConverter end 3) Call the method in your view #app/views/courses/show.html.erb <%= course.determine_tagline %> If my taglines change they can be changed in one place. This example[…]

Ruby provides a module level getter/setter shortcut named mattr_accessor. This is the Module level version of the more commonly observed attr_accessor and class level accessor name cattr_accessor. require ‘rails’   module MastersLevel mattr_accessor :valedictorian self.valedictorian = "The Good Learner" end   class SeniorYear include MastersLevel mattr_accessor :valedictorian end   class JuniorYear include MastersLevel end   p MastersLevel.valedictorian #=> "The Good Learner"   p SeniorYear.valedictorian #=> "The Good Learner"   p JuniorYear.valedictorian rubys_mattr_accessor.rb:17:in `<main>’: undefined method `valedictorian’ for SeniorYear:Class (NoMethodError) This is another way we can pass a module method around our application. :)