I've been looking at some examples on how tap can be used, and I'm not sure how it can be used to write flexible code
For example
http://blog.moertel.com/posts/2007-02-07-ruby-1-9-gets-handy-new-method-object-tap.html
http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions
Given that RM scripting is mostly about chain aliasing, and tap is meant to help with chain calling, it seems like something can be done here.
So say I had a method that adds two numbers together
def my_sum(a, a + bendAnd then I wanted to add some logic, I could say
Or I could say
But this is a trivial example and isn't something that I would be putting in released scripts.Are there any use cases where tap would provide MORE flexibility over simply aliasing?
For example
http://blog.moertel.com/posts/2007-02-07-ruby-1-9-gets-handy-new-method-object-tap.html
http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions
Given that RM scripting is mostly about chain aliasing, and tap is meant to help with chain calling, it seems like something can be done here.
So say I had a method that adds two numbers together
def my_sum(a, a + bendAnd then I wanted to add some logic, I could say
Code:
alias :th_my_sum :my_sumdef my_sum(a, res = th_my_sum(a, p res resend
Code:
alias :th_my_sum :my_sumdef my_sum(a, th_my_sum(a, .tap {|res| p res }end