Skip to content

Instantly share code, notes, and snippets.

@thiagofm
Created November 17, 2014 20:39
Show Gist options
  • Save thiagofm/8c7c4cc2be8d45f285ea to your computer and use it in GitHub Desktop.
Save thiagofm/8c7c4cc2be8d45f285ea to your computer and use it in GitHub Desktop.
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
Copy link

module Foo

  def respond_to(name)
    define_method(name) { "i have #{name} on #{self.class}" }
  end

end

class ModelFoo
  extend Foo

  def foo
    "oops"
  end

  respond_to 'foo'
end

class ModelBar
  extend Foo
  respond_to 'bar'
end


foo = ModelFoo.new
foo.foo

@alexandreprates
Copy link

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