Created
September 21, 2012 16:22
-
-
Save clayallsopp/3762453 to your computer and use it in GitHub Desktop.
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
a = 3 | |
a.class.instance_eval do | |
define_method :my_method, ->(arg1 = :my_arg, *args, &block) do | |
p "arg1 #{arg1} args #{args.inspect}" | |
block.call | |
end | |
end | |
(main)> a.my_method(:my_arg_really, 1, 2, 3, 4, 5) do | |
(main)> p "Hello!" | |
(main)> end | |
"arg1 my_arg_really args [1, 2, 3, 4, 5]" | |
"Hello!" | |
=> "Hello1!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if i replace instance_eval by class_eval, still it works :) ( ruby 1.9 )