Tivoli

en.wikipedia.org/wiki/Aspect-oriented_programming

Usage

t = Tivoli.new(String.instance_method(:+))
t.aspect :before { |time, args, &block|
  # log stuff here or
  puts "LOG #{args}"
}
"hello" + "other" # => 'helloother'
LOG ['other']

t.aspect :before { |time, args, &block| 
  # change arguments
  args[0].reverse!
}
'hello' + 'other' # => 'helloretho'

# prev is used for chaining multiple filters, first time prev is nil
t.filter :before { |prev, time, args, &block| 
  # change result
  'nope'
}
'hello' + 'other' # => 'nope'

t.aspect :before {
  sleep 1
}
t.filter :after { |prev, time, args, &block|
  prev + time
}
"hello" + "other" # => 'helloother1000'

Contributing to tivoli

Copyright © 2011 Erik Fonselius. See LICENSE.txt for further details.