Created
February 12, 2009 12:12
-
-
Save fsvehla/62595 to your computer and use it in GitHub Desktop.
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 DeepFreezing | |
| # „Deep freezes“ the array, that is: | |
| # - if the element responds to deep_freeze itself, | |
| # like Array and Hash should, call it. | |
| # - if the element responds to freeze, call it | |
| # - freeze self | |
| # | |
| # ==== Returns | |
| # self | |
| # | |
| # ==== Considerations | |
| # Circular references are not resolved and might result in a deadlock, | |
| # so don't do that. | |
| def deep_freeze | |
| self.each do |element| | |
| if element.respond_to?(:deep_freeze) | |
| element.deep_freeze | |
| elsif element.respond_to?(:freeze) | |
| element.freeze | |
| end | |
| end | |
| self.freeze | |
| self | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment