It decorates an existing Ruby object and intercepts all calls to all its methods:
require 'intercepted'
i = intercepted(42) do |e, m, args, r|
if e == :after
puts "#{m}(#{args.join(', ')}) -> #{r}"
end
end
puts i + 4
Prints:
+(4) -> 46
The value of e
may either be :after
or :before
.
The value of m
is the name of the method called (a symbol).
The list of arguments passed are in the args
.
The result of method execution is in the r
(it's nil when e
is :before
).
That's it.
Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then run:
bundle update
bundle exec rake
If it's clean and you don't see any error messages, submit your pull request.