class Parameters::InstanceParam

Attributes

object[R]

Owning object

Public Class Methods

new(object,name,type=nil,description=nil,value=nil) click to toggle source

Creates a new InstanceParam object.

@param [Object] object

The object containing the instance variable for the instance
parameter.

@param [Symbol, String] name

The name of the instance parameter.

@param [Class, Array] type

The enforced type of the instance parameter.

@param [String, nil] description

The description of the instance parameter.

@param [Object] value

The initial value for the instance parameter.

@api semipublic

Calls superclass method
# 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

Public Instance Methods

inspect() click to toggle source

Inspects the instance parameter.

@return [String]

Inspection of the instance params value.
# File lib/parameters/instance_param.rb, line 93
def inspect
  "#<#{self.class}: #{value.inspect}>"
end
to_s() click to toggle source

@return [String]

Representation of the instance param.
# 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() click to toggle source

@return

The value of the instance param.
# File lib/parameters/instance_param.rb, line 57
def value
  @object.instance_variable_get(:"@#{@name}")
end
value=(value) click to toggle source

Sets the value of the instance param.

@param [Object] value

The new value of the instance param.

@return [Object]

The new value of the instance param.
# File lib/parameters/instance_param.rb, line 70
def value=(value)
  @object.instance_variable_set(:"@#{@name}",coerce(value))
end