Skip to content

Instantly share code, notes, and snippets.

@oinak
Created June 10, 2015 09:34
Show Gist options
  • Save oinak/fec2c80997df81412c5d to your computer and use it in GitHub Desktop.
Save oinak/fec2c80997df81412c5d to your computer and use it in GitHub Desktop.
Primer ejercicio del taller de metaprogramación
module Includeable
def have_module
"metodo desde Includeable"
end
def self.included(mod)
puts "Includeable incluido en #{mod}"
end
end
class First
include Includeable
def say_hi
"soy un metodo de instancia de First"
end
def self.inherited(kla)
"First ha sido heredado por #{kla}"
end
end
module JezExtender
def long?
"8" + "="*20 + "D"
end
def self.extended(mod)
puts "#{self} extendiendo a #{mod}"
end
end
class Second < First
include Includeable
extend JezExtender
def say_bye
"hasta la vista"
end
end
f = First.new
s = Second.new
puts "\nf.have_module => #{f.have_module}"
puts "\ns.say_hi => #{s.say_hi}"
puts "\nSecond.long? => #{Second.long?}"
puts "\ns.say_bye => #{s.say_bye}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment