Skip to content

Instantly share code, notes, and snippets.

@shivabhusal
Last active June 23, 2017 17:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shivabhusal/3a427a141b1d0813c5b97175927943a8 to your computer and use it in GitHub Desktop.
Ruby creates an anonymous class with the name of the module you are including and puts it in the ancestors chain.
module Printable
def print(message)
puts message
end
end
class Animal
include Printable
def speak
print("##")
end
end
class Cow < Animal
def speak
print("MOO")
end
end
# > Cow.ancestors
# => [Cow, Animal, Printable, Object, PP::ObjectMixin, Kernel, BasicObject]
# 'superclass' method skips the Printable module
# > Animal.superclass
# => Object
cow = Cow.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment