Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2012 15:43
Show Gist options
  • Save anonymous/4420790 to your computer and use it in GitHub Desktop.
Save anonymous/4420790 to your computer and use it in GitHub Desktop.
define_method seems to know whether it's in a class scope or subscope. (?????)
class Log1Buffer < ::Array
for meth in PUBLIC_METHODS = %w(debug info warn error fatal).map(&:to_sym)
define_method(meth){|*a| push [meth, *a] }
end
end
1.9.3p194 :062 > buffer.debug "something"
=> [[:fatal, "something"]]
class Log2Buffer < ::Array
define_method(:debug){|*a| push [:debug, *a] }
define_method(:info){|*a| push [:info, *a] }
define_method(:warn){|*a| push [:warn, *a] }
define_method(:error){|*a| push [:error, *a] }
define_method(:fatal){|*a| push [:fatal, *a] }
end
* works as expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment