Sha256: 94eed50d3cb9be253e100fa2e451ba70679d882b9075e2dc9e5e2a10ec5f0b75

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 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}")
    end

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

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

      text << " [#{value}]" 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

1 entries across 1 versions & 1 rubygems

Version Path
parameters-0.1.1 lib/parameters/instance_param.rb