Class: Parameters::InstanceParam
- Defined in:
- lib/parameters/instance_param.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Owning object.
Attributes inherited from Param
Instance Method Summary collapse
-
#initialize(object, name, type = nil, description = nil, value = nil) ⇒ InstanceParam
constructor
Creates a new InstanceParam object.
-
#inspect ⇒ String
Inspects the instance parameter.
-
#to_s ⇒ String
Representation of the instance param.
-
#value ⇒ Object
The value of the instance param.
-
#value=(value) ⇒ Object
Sets the value of the instance param.
Methods inherited from Param
Constructor Details
#initialize(object, name, type = nil, description = nil, value = nil) ⇒ InstanceParam
Creates a new InstanceParam object.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/parameters/instance_param.rb', line 30 def initialize(object,name,type=nil,description=nil,value=nil) super(name,type,description) @object = object if (self.value.nil? && !value.nil?) self.value = case value when Proc if value.arity > 0 value.call(@object) else value.call() end else begin value.clone rescue TypeError value end end end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Owning object
7 8 9 |
# File 'lib/parameters/instance_param.rb', line 7 def object @object end |
Instance Method Details
#inspect ⇒ String
Inspects the instance parameter.
93 94 95 |
# File 'lib/parameters/instance_param.rb', line 93 def inspect "#<#{self.class}: #{value.inspect}>" end |
#to_s ⇒ String
Returns Representation of the instance param.
78 79 80 81 82 83 84 85 |
# File 'lib/parameters/instance_param.rb', line 78 def to_s text = @name.to_s text << "\t[#{value.inspect}]" if value text << "\t#{@description}" if @description return text end |
#value ⇒ Object
Returns The value of the instance param.
57 58 59 |
# File 'lib/parameters/instance_param.rb', line 57 def value @object.instance_variable_get(:"@#{@name}") end |
#value=(value) ⇒ Object
Sets the value of the instance param.
70 71 72 |
# File 'lib/parameters/instance_param.rb', line 70 def value=(value) @object.instance_variable_set(:"@#{@name}",coerce(value)) end |