In Ruby, there’s often more than one way to do something. The language
contains a lot of synonyms such as Enumerable#reduce and
Enumerable#inject. It also contains a number of work-alikes such as
hash literals like {} and hash constructors like Hash.new.
In general, programmers can treat this cornucopia of syntax as a matter of personal preference, or choose synonyms to communicate more clearly about the intent of a given piece of code. However, there are cases where work-alikes are not identical in terms of performance. Let’s look at some of those use cases.