Skip to content

Instantly share code, notes, and snippets.

@scaint
Created January 29, 2014 15:59
Show Gist options
  • Select an option

  • Save scaint/8691054 to your computer and use it in GitHub Desktop.

Select an option

Save scaint/8691054 to your computer and use it in GitHub Desktop.
An approach to emulate Array::map for single objects
# 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