lib/parameters/instance_param.rb in parameters-0.1.9 vs lib/parameters/instance_param.rb in parameters-0.2.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'parameters/param' + module Parameters class InstanceParam < Param # Owning object attr_reader :object @@ -12,25 +14,28 @@ # parameter. # # @param [Symbol, String] name # The name of the instance parameter. # + # @param [Class, Array[Class]] type + # The enforced type of the instance parameter. + # # @param [String, nil] description # The description of the instance parameter. # - def initialize(object,name,description=nil) - super(name,description) + def initialize(object,name,type=nil,description=nil) + super(name,type,description) @object = object end # # @return # The value of the instance param. # def value - @object.instance_variable_get("@#{@name}".to_sym) + @object.instance_variable_get(:"@#{@name}") end # # Sets the value of the instance param. # @@ -39,10 +44,10 @@ # # @return [Object] # The new value of the instance param. # def value=(value) - @object.instance_variable_set("@#{@name}".to_sym,value) + @object.instance_variable_set(:"@#{@name}",coerce(value)) end # # @return [String] # Representation of the instance param.