Skip to content

Commit

Permalink
! Revert Make code "Object Shape friendly"
Browse files Browse the repository at this point in the history
Fix issue happening on production environment
  • Loading branch information
PikachuEXE committed Oct 11, 2023
1 parent 875c586 commit f5ae5ad
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/contracted_value/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ def initialize(input_attr_values = {})
)
end

@attr_values = {}

self.class.send(:attribute_set).each_attribute do |attribute|
attr_value = attribute.extract_value(input_attr_values_hash)

Expand All @@ -262,8 +260,8 @@ def initialize(input_attr_values = {})

# Using symbol since attribute names are limited in number
# An alternative would be using frozen string
@attr_values.store(
attribute.name.to_sym,
instance_variable_set(
:"@#{attribute.name}",
sometimes_frozen_attr_value,
)
end
Expand All @@ -274,7 +272,10 @@ def initialize(input_attr_values = {})
# rubocop:enable Metrics/CyclomaticComplexity

def to_h
@attr_values.clone
self.class.send(:attribute_set).
each_attribute.each_with_object({}) do |attribute, hash|
hash[attribute.name] = instance_variable_get(:"@#{attribute.name}")
end
end

# == Class interface == #
Expand Down Expand Up @@ -306,7 +307,7 @@ def attribute(
)
@attribute_set = @attribute_set.add(attr)

define_method(name_in_sym) { @attr_values[name_in_sym] }
attr_reader(name_in_sym)
end

# @api private
Expand Down

0 comments on commit f5ae5ad

Please sign in to comment.