Last active
January 8, 2020 03:01
-
-
Save havenwood/744b0d114da82ac1f9c124be649421b2 to your computer and use it in GitHub Desktop.
My refinement suggestion for a #ruby IRC question about monkey patching
This file contains 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
module SizeSquared | |
[String, Enumerable].each do |this_class| | |
refine this_class do | |
def size_squared | |
size.abs2 | |
end | |
alias length_squared size_squared | |
end | |
end | |
end | |
using SizeSquared | |
'ule'.length_squared | |
#=> 9 | |
5.times.size_squared | |
#=> 25 | |
[].size_squared | |
#=> 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment