Module: Adamantium
- Defined in:
- lib/adamantium.rb,
lib/adamantium/freezer.rb,
lib/adamantium/version.rb,
lib/adamantium/class_methods.rb,
lib/adamantium/module_methods.rb
Overview
Allows objects to be made immutable
Defined Under Namespace
Modules: ClassMethods, Flat, ModuleMethods Classes: Freezer
Constant Summary collapse
- Memory =
Storage for memoized methods
Class.new(::Hash)
- VERSION =
Released gem version
'0.0.7'.freeze
Class Method Summary collapse
-
.included(descendant) ⇒ self
private
Hook called when module is included.
Instance Method Summary collapse
-
#dup ⇒ self
A noop #dup for immutable objects.
-
#freeze ⇒ Object
Freeze the object.
-
#memoize(name, value) ⇒ self
Sets a memoized value for a method.
-
#memoized(name) ⇒ Object
Get the memoized value for a method.
Class Method Details
.included(descendant) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hook called when module is included
47 48 49 50 51 |
# File 'lib/adamantium.rb', line 47 def self.included(descendant) descendant.extend ModuleMethods if descendant.kind_of?(Module) descendant.extend ClassMethods if descendant.kind_of?(Class) self end |
Instance Method Details
#dup ⇒ self
A noop #dup for immutable objects
109 110 111 |
# File 'lib/adamantium.rb', line 109 def dup self end |
#freeze ⇒ Object
Freeze the object
61 62 63 64 |
# File 'lib/adamantium.rb', line 61 def freeze memory # initialize memory super end |
#memoize(name, value) ⇒ self
Sets a memoized value for a method
94 95 96 97 98 99 |
# File 'lib/adamantium.rb', line 94 def memoize(name, value) unless memory.key?(name) store_memory(name, freeze_object(value)) end self end |
#memoized(name) ⇒ Object
Get the memoized value for a method
77 78 79 |
# File 'lib/adamantium.rb', line 77 def memoized(name) memory[name] end |