Skip to content

Instantly share code, notes, and snippets.

@jpterry
Created February 5, 2013 02:53
Show Gist options
  • Save jpterry/4711762 to your computer and use it in GitHub Desktop.
Save jpterry/4711762 to your computer and use it in GitHub Desktop.
Including a module in ruby inherits nested classes. This is an example.
module JohnsThings
class AwesomeTool
def is_awesome?
true
end
end
end
class HurricaneTool
include JohnsThings
def is_awesome?
AwesomeTool.new.is_awesome? # This works! Even though I'm not in JohnsThings namespace
end
end
ht = HurricaneTool.new.is_awesome? #=> true
HurricaneTool::AwesomeTool #=> JohnsThings::AwesomeTool
@loveybot
Copy link

loveybot commented Feb 5, 2013

Yay Ruby!!

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