Skip to content

Instantly share code, notes, and snippets.

@myitcv
Last active December 29, 2015 22:59
Show Gist options
  • Save myitcv/7740359 to your computer and use it in GitHub Desktop.
Save myitcv/7740359 to your computer and use it in GitHub Desktop.
Differences in define_method
module V1
def self.doit(opts = {})
opts.each_pair do |k,v|
define_method(k, &v)
end
end
doit a: -> { b }
doit b: -> { 'b' }
end
module V2
def self.doit(opts = {})
opts.each_pair do |k,v|
define_method(k) {
v.call
}
end
end
doit a: -> { b }
doit b: -> { 'b' }
end
class A
include V1
end
class B
include V2
end
a = A.new
puts a.a
b = B.new
puts b.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment