Skip to content

Instantly share code, notes, and snippets.

@clayallsopp
Created September 21, 2012 16:22
Show Gist options
  • Save clayallsopp/3762453 to your computer and use it in GitHub Desktop.
Save clayallsopp/3762453 to your computer and use it in GitHub Desktop.
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
@psahni
Copy link

psahni commented Sep 21, 2012

if i replace instance_eval by class_eval, still it works :) ( ruby 1.9 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment