Skip to content

Instantly share code, notes, and snippets.

@ihower
Created August 21, 2010 05:40
Show Gist options
  • Save ihower/541832 to your computer and use it in GitHub Desktop.
Save ihower/541832 to your computer and use it in GitHub Desktop.
# idea from http://www.codemud.net/~thinker/GinGin_CGI.py/show_id_doc/201
def log(logfile):
def assign_call(call):
return lambda *args, **kws: logfile.write(call.__name__) and call(*args, **kws)
return assign_call
class Foo(object):
@log(file('my.log',"w"))
def bar():
pass
f = Foo()
f.bar()
f.bar()
class Class
def log(name, logfile)
original_c_m = instance_method(name)
define_method name do |*args|
logfile.write caller
original_c_m.bind(self).call(*args)
end
end
end
class Foo
def foo
end
log :foo, File.new("my.log", "w")
end
f = Foo.new
f.foo
f.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment