Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Alfa
def self.included(base)
puts "#{self} included in #{base}"
unless base.const_defined?(:PAPPA)
base.const_set :PAPPA, [:a, :b]
end
end
def self.extended(base)
puts "#{self} extended in #{base}"
unless base.const_defined?(:PAPPA)
base.const_set :PAPPA, [:a, :b]
end
end
def papa
p self::PAPPA
end
end
module Beta
PAPPA = [1, 2]
extend Alfa
def self.hola
papa
end
end
class Teta
include Alfa
def initialize()
# just to keep in mind that this is a class that we'll instantiate
end
def hola
papa
end
end
puts "from Beta #{Beta.hola}"
puts "from Teta #{Teta.new().hola}"
@enricostano
Copy link
Author

enricostano commented May 22, 2014

This is what I get:

Alfa extended in Beta
Alfa included in Teta
[1, 2]
from Beta [1, 2]
puppa.rb:17:in `papa': #<Teta:0x007f9b30b27028> is not a class/module (TypeError)
    from puppa.rb:36:in `hola'
    from puppa.rb:41:in `<main>'

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