Created
January 5, 2009 08:47
-
-
Save bruce/43329 to your computer and use it in GitHub Desktop.
This file contains 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
$:.unshift(File.dirname(__FILE__) << '/../lib') | |
require 'clingwrap' | |
class Widget | |
def do_something | |
sleep 0.12 | |
puts "Did something!" | |
end | |
end | |
module DoSomethingPreparation | |
def do_something | |
puts "(prepwork for Widget#do_something)" | |
super | |
end | |
end | |
Widget.clingwrap(DoSomethingPreparation) | |
Widget.clingwrap "Time invocation" do | |
def do_something | |
start = Time.now | |
result = super | |
puts "Elapsed: %.4fs" % (Time.now - start) | |
result | |
end | |
end | |
widget = Widget.new | |
widget.do_something | |
puts "\nUsing super-and-extend, not just an alias hack!" | |
puts "---\nIt also gives anonymous wrappers pretty names when inspected:" | |
p (class << widget; self; end).ancestors | |
This file contains 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
(prepwork for Widget#do_something) | |
Did something! | |
Elapsed: 0.1201s | |
Using super-and-extend, not just an alias hack! | |
--- | |
It also gives anonymous wrappers pretty names when inspected: | |
[(Wrapper:"Time invocation" @ simple.rb:21), DoSomethingPreparation, Widget, Object, Kernel] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment