Last active
August 29, 2015 14:01
-
-
Save oinak/09b3c2c21f378544aa18 to your computer and use it in GitHub Desktop.
Tercer ejercicio del taller de metaprogramación
This file contains hidden or 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 Donor | |
def foo(extra) | |
puts "bar #{extra}" | |
end | |
def not_foo | |
puts "not bar" | |
end | |
end | |
module Extractor | |
def pick(method_name, module_obj) | |
# si captura aqui, se queda cacheada la implementacion | |
define_method(method_name) do |*args| | |
module_obj.instance_method(method_name).bind(self)[*args] | |
end | |
end | |
end | |
class Three | |
extend Extractor | |
pick :foo, Donor | |
end | |
three = Three.new | |
three.foo('plas') | |
begin | |
three.not_foo | |
rescue | |
puts "cazado" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment