Created
July 7, 2017 09:03
-
-
Save ritikesh/e1bb9fae8a186e69c5ca15219c91cf9f to your computer and use it in GitHub Desktop.
Simple deep freeze for Ruby Enumerables
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
module Enumerable | |
def deep_freeze | |
obj = self | |
obj.each do |iterator| | |
case iterator | |
when Enumerable | |
iterator.deep_freeze | |
when Symbol, Fixnum, NilClass | |
iterator | |
else | |
iterator.freeze | |
end | |
end.freeze | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment