Skip to content

Instantly share code, notes, and snippets.

@ritikesh
Created July 7, 2017 09:03
Show Gist options
  • Save ritikesh/e1bb9fae8a186e69c5ca15219c91cf9f to your computer and use it in GitHub Desktop.
Save ritikesh/e1bb9fae8a186e69c5ca15219c91cf9f to your computer and use it in GitHub Desktop.
Simple deep freeze for Ruby Enumerables
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