malkomalko
9/24/2012 - 3:46 PM

gistfile1.rb

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