When I first saw Ruby 1.9 new method Object#tap I slightly overlooked it and felt that this method may not be useful. But recently in one of my project I realized that how it can improve the reability of the code and avoids un-necessary return statements.
1 2 3 4 5 6 7 8 9 10 | |
If we want to print and return the student object after creating it, without tap the code will look like:
1 2 3 4 5 6 7 | |
The same can be made more readable and prettier with the help of tap
1 2 3 4 5 | |