module Adamantium

Allows objects to be made immutable

Constants

VERSION

Gem version

Private Class Methods

included(descendant) click to toggle source

Hook called when module is included

@param [Module] descendant

the module or class including Adamantium

@return [self]

@api private

Calls superclass method
# File lib/adamantium.rb, line 47
def self.included(descendant)
  super
  descendant.class_eval do
    include Memoizable
    extend ModuleMethods
    extend ClassMethods if kind_of?(Class)
  end
end

Public Instance Methods

__adamantium_dup__()

Alias to the original dup method

@return [Object]

@api private

Alias for: dup
dup() click to toggle source

A noop dup for immutable objects

@example

object.dup  # => self

@return [self]

@api public

# File lib/adamantium.rb, line 73
def dup
  self
end
Also aliased as: __adamantium_dup__

Protected Instance Methods

transform(&block) click to toggle source

Transform the object with the provided block

@return [Object]

@api public

# File lib/adamantium.rb, line 84
def transform(&block)
  copy = __adamantium_dup__
  copy.instance_eval(&block)
  self.class.freezer.freeze(copy)
end
transform_unless(condition, &block) click to toggle source

Transform the object with the provided block if the condition is false

@param [Boolean] condition

@return [Object]

@api public

# File lib/adamantium.rb, line 97
def transform_unless(condition, &block)
  condition ? self : transform(&block)
end