Created
January 29, 2014 15:59
-
-
Save scaint/8691054 to your computer and use it in GitHub Desktop.
An approach to emulate Array::map for single objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Using instance_eval | |
| # Time: 0.267886376 | |
| Benchmark.measure do | |
| 1000000.times { 1.instance_eval { self+1 } } # => 2 | |
| end | |
| # Using tap+break | |
| # Time: 0.304528147 | |
| Benchmark.measure do | |
| 1000000.times { 1.tap { |o| break o+1 } } # => 2 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment