Class: NRSER::Props::Storage::InstanceVariables
- Defined in:
- lib/nrser/props/storage/instance_variables.rb
Instance Method Summary collapse
- #get(instance, prop) ⇒ Object
- #immutable? ⇒ Boolean
-
#initialize(immutable:) ⇒ InstanceVariables
constructor
A new instance of InstanceVariables.
- #put(instance, prop, value) ⇒ Object
Constructor Details
#initialize(immutable:) ⇒ InstanceVariables
33 34 35 |
# File 'lib/nrser/props/storage/instance_variables.rb', line 33 def initialize immutable: @immutable = !!immutable end |
Instance Method Details
#get(instance, prop) ⇒ Object
43 44 45 |
# File 'lib/nrser/props/storage/instance_variables.rb', line 43 def get instance, prop instance.instance_variable_get "@#{ prop.name }" end |
#immutable? ⇒ Boolean
38 39 40 |
# File 'lib/nrser/props/storage/instance_variables.rb', line 38 def immutable? @immutable end |
#put(instance, prop, value) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nrser/props/storage/instance_variables.rb', line 48 def put instance, prop, value if immutable? raise RuntimeError.new binding.erb " Properties of \#{ instance.class.safe_name } are immutable.\n \n Tried to set prop \#{ prop.name } to value\n \n <%= value.pretty_inspect %>\n \n in instance\n \n <%= instance.pretty_inspect %>\n \n END\n end\n \n instance.instance_variable_set \"@\#{ prop.name }\", value\nend\n" |