Module: MoveToGo::ImmutableModel
- Defined in:
- lib/move-to-go/model_helpers.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.immutable_accessor(name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/move-to-go/model_helpers.rb', line 38 def self.immutable_accessor(name) define_method(name) do return instance_variable_get("@#{name}") end define_method("#{name}=") do |value| raise_if_immutable instance_variable_set("@#{name}", value) end end |
Instance Method Details
#is_immutable ⇒ Object
55 56 57 |
# File 'lib/move-to-go/model_helpers.rb', line 55 def is_immutable() @is_immutable = true end |
#raise_if_immutable ⇒ Object
49 50 51 52 53 |
# File 'lib/move-to-go/model_helpers.rb', line 49 def raise_if_immutable if @is_immutable raise ObjectIsImmutableError end end |