Created
November 17, 2014 20:39
-
-
Save thiagofm/8c7c4cc2be8d45f285ea to your computer and use it in GitHub Desktop.
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 Lib | |
def xpto(option) | |
mod = Module.new | |
include mod | |
mod.class_eval <<-RUBY, __FILE__, __LINE__+1 | |
def #{option} | |
1 | |
end | |
RUBY | |
end | |
end | |
class Model | |
extend Lib | |
xpto 'a' | |
end | |
m = Model.new | |
p m.a # 1 |
alexandreprates
commented
Nov 17, 2014
module Foo
def respond_to(name)
define_method(name) { "i have #{name} on #{self.class}" }
end
end
class ModelFoo
extend Foo
respond_to 'foo'
def foo
"oops"
end
end
foo = ModelFoo.new
foo.foo
# => 'oops'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment