Created
December 31, 2012 15:43
-
-
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. (?????)
This file contains hidden or 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
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