Created
May 22, 2014 15:53
-
-
Save enricostano/c367aac670b574af93e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what I get: