Sha256: 236aa7809b99f12adaf2c23a6b32da775a3156ea48ada37d03795141cef34f5b
Contents?: true
Size: 1.56 KB
Versions: 2
Compression:
Stored size: 1.56 KB
Contents
require 'parameters/param' module Parameters class InstanceParam < Param # Owning object attr_reader :object # # 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[Class]] type # The enforced type of the instance parameter. # # @param [String, nil] description # The description of the instance parameter. # 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}") end # # 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. # def value=(value) @object.instance_variable_set(:"@#{@name}",coerce(value)) end # # @return [String] # Representation of the instance param. # def to_s text = @name.to_s text << " [#{value.inspect}]" if value text << "\t#{@description}" if @description return text end # # Inspects the instance parameter. # # @return [String] # Inspection of the instance params value. # def inspect "#<#{self.class}: #{value.inspect}>" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
parameters-0.2.3 | lib/parameters/instance_param.rb |
parameters-0.2.2 | lib/parameters/instance_param.rb |