Skip to content

Instantly share code, notes, and snippets.

@jdar
Forked from anonymous/gist:4420790
Last active December 10, 2015 16:48
Show Gist options
  • Save jdar/4463481 to your computer and use it in GitHub Desktop.
Save jdar/4463481 to your computer and use it in GitHub Desktop.
I'm sad that this is the solution.
class Log1Buffer < ::Array
for meth in PUBLIC_METHODS = %w(debug info warn error fatal).map(&:to_sym)
eval "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