module
Module Mixin
extend vs. include in classes
extend vs. include in classesmodule Animals
def mammals
["sloths", "puppies", "porcupines"]
end
end
# - - - - - - - - include
class Zoo
include Animals
end
zoo = Zoo.new
zoo.mammals # => ["sloths", "puppies", "porcupines"]
zoo.methods - Object.methods # => mammals
# - - - - - - - - extend
class PetStore
extend Animals
end
PetStore.mammals # => ["sloths", "puppies", "porcupines"]
pet_store = PetStore.new
pet_store.mammals # => undefined method `mammals' for #<PetStore:0x007f858a919f30> (NoMethodError)
PetStore.methods - Object.methods # => mammals
pet_store = PetStore.new
pet_store.methods - Object.methods # =>Module Methods
extend self
extend selfself method name prefix
self method name prefixLast updated