Created
September 16, 2011 04:02
-
-
Save neilconway/1221171 to your computer and use it in GitHub Desktop.
instance_exec + blocks
This file contains 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
class X | |
def self.morph(name, &blk) | |
define_method(name) do |*args, &user_blk| | |
instance_exec(*args, &blk) | |
end | |
end | |
morph :xyz do |a, b, &blk| | |
puts "HELLO, WORLD!" | |
blk.call(a, b) | |
end | |
end | |
X.new.xyz(5, 10) {|a, b| puts "YAY! a = #{a}; b = #{b}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment