Module: Adamantium
- Defined in:
- lib/adamantium.rb,
lib/adamantium/freezer.rb,
lib/adamantium/mutable.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, Mutable Classes: Freezer
Constant Summary collapse
- Memory =
Storage for memoized methods
Class.new(::Hash)
- VERSION =
Gem version
'0.0.11'.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
48 49 50 51 52 |
# File 'lib/adamantium.rb', line 48 def self.included(descendant) descendant.extend ModuleMethods descendant.extend ClassMethods if descendant.kind_of?(Class) self end |
Instance Method Details
#dup ⇒ self
A noop #dup for immutable objects
110 111 112 |
# File 'lib/adamantium.rb', line 110 def dup self end |
#freeze ⇒ Object
Freeze the object
62 63 64 65 |
# File 'lib/adamantium.rb', line 62 def freeze memory # initialize memory super end |
#memoize(name, value) ⇒ self
Sets a memoized value for a method
95 96 97 98 99 100 |
# File 'lib/adamantium.rb', line 95 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
78 79 80 |
# File 'lib/adamantium.rb', line 78 def memoized(name) memory[name] end |