Sha256: 74893c1cf17ef23aebe5c3aff1852310b690288acfb107c78443776b262b097b

Contents?: true

Size: 965 Bytes

Versions: 2

Compression:

Stored size: 965 Bytes

Contents

module Parameters
  class InstanceParam < Param

    # Owning object
    attr_reader :object

    #
    # Creates a new InstanceParam object with the specified _object_ and
    # _name_, and the given _description_.
    #
    def initialize(object,name,description=nil)
      super(name,description)

      @object = object
    end

    #
    # Returns the value of the instance param.
    #
    def value
      @object.instance_variable_get("@#{@name}".to_sym)
    end

    #
    # Sets the value of the instance param.
    #
    def value=(value)
      @object.instance_variable_set("@#{@name}".to_sym,value)
    end

    #
    # Returns a String representation of the instance param.
    #
    def to_s
      text = "  #{@name}"

      text << " [#{value.inspect}]" if value
      text << "\t#{@description}" if @description

      return text
    end

    #
    # Inspects the instance params value.
    #
    def inspect
      value.inspect
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parameters-0.1.5 lib/parameters/instance_param.rb
parameters-0.1.6 lib/parameters/instance_param.rb