Shopify / measured

Encapsulate measurements and their units in Ruby and Ruby on Rails.
MIT License
337 stars 28 forks source link

`convert_to!` shouldn't do a heap allocation #37

Closed thegedge closed 7 years ago

thegedge commented 7 years ago

Measurable#convert_to! calls Measurable#convert_to to perform its operation. In-place operations are often used for performance reasons, and should not cause (unnecessary) allocations. convert_to! should do so, and convert_to should be written as self.dup.convert_to!(unit)

That being said the better option here is to just drop convert_to! in favour of immutability.

kmcphillips commented 7 years ago

self.dup.convert_to!(unit) Oh I like that.

But we should probably favour immutability.