Class: EacRubyUtils::ActsAsImmutable::CommonAccessor
Constant Summary
Constants inherited
from BaseAccessor
BaseAccessor::FILTER_GET_METHOD_NAME_FORMAT, BaseAccessor::FILTER_SET_METHOD_NAME_FORMAT
Instance Method Summary
collapse
#duplicate_object, #immutable_value_get_filtered, #immutable_value_get_filtered_method_name, #immutable_value_set_filtered, #immutable_value_set_filtered_method_name
Instance Method Details
#apply(klass) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb', line 9
def apply(klass)
accessor = self
klass.send(:define_method, name) do |*args|
case args.count
when 0 then next accessor.immutable_value_get_filtered(self)
when 1 then next accessor.immutable_value_set_filtered(self, args.first)
else
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
end
end
end
|
#immutable_value_get(object) ⇒ Object
21
22
23
|
# File 'lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb', line 21
def immutable_value_get(object)
object.send(:immutable_values_get)[name]
end
|
#immutable_value_set(object, value) ⇒ Object
25
26
27
|
# File 'lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb', line 25
def immutable_value_set(object, value)
duplicate_object(object) { |_old_value| value }
end
|