Skip to content

Instantly share code, notes, and snippets.

@gcao
Created June 7, 2010 21:39
Show Gist options
  • Save gcao/429233 to your computer and use it in GitHub Desktop.
Save gcao/429233 to your computer and use it in GitHub Desktop.
class A
include Aspect4r
def test value
puts 'test'
value
end
around :test do |proxy, value|
puts 'around 1'
result = a4r_invoke proxy, value
puts 'around 2'
result
end
before_filter :test do |value|
puts 'before_filter'
value >= 0
end
before :test do |value|
puts 'before'
end
after :test do |result, value|
puts 'after'
result
end
end
puts A.new.test(1)
# ==== Output ====
# before_filter
# before
# around 1
# test
# around 2
# after
# 1
puts A.new.test(-1)
# ==== Output ====
# before_filter
@gcao
Copy link
Author

gcao commented Jun 8, 2010

class A
include Aspect4r

before :test, :validate
after :test, :handle_result

def test value
value
end

def validate value
end

def handle_result result, value
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment