Last active
December 29, 2015 22:59
-
-
Save myitcv/7740359 to your computer and use it in GitHub Desktop.
Differences in define_method
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 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