Class: RFunk::Immutable

Inherits:
Object
  • Object
show all
Defined in:
lib/rfunk/attribute/immutable.rb

Instance Method Summary collapse

Instance Method Details

#create(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rfunk/attribute/immutable.rb', line 3

def create(options)
  instance = options.fetch(:instance)
  variable_name = options.fetch(:variable_name)
  value = options.fetch(:value)

  instance.class.new.tap do |object|
    create_instance_variables(instance, object, variable_name)

    object.instance_variable_set(variable_name, value)
    object.deep_freeze if should_deep_freeze?(value)
  end
end