Skip to content

Instantly share code, notes, and snippets.

@kzgs
Created September 10, 2011 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzgs/1207992 to your computer and use it in GitHub Desktop.
Save kzgs/1207992 to your computer and use it in GitHub Desktop.
define_method & block argument
puts "#{"-"*10} ruby #{RUBY_VERSION} #{"-"*10}"
module A
class << self
define_method(:mymethod) do |arg1, arg2, &block|
x = 1
puts "arg1:#{arg1}"
puts "arg2:#{arg2}"
block.call(x)
end
end
end
A.mymethod("a","b") do |x|
puts "x=#{x}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment