Sha256: fa42c9f6fe40447cc05c8d1efebf5581a9393a62f0271a5ecd9f2de62d6e3a1b

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

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 [String, nil] description
    #   The description of the instance parameter.
    #
    def initialize(object,name,description=nil)
      super(name,description)

      @object = object
    end

    #
    # @return
    #   The value of the instance param.
    #
    def value
      @object.instance_variable_get("@#{@name}".to_sym)
    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}".to_sym,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

    #
    # @return [String]
    #   Inspection of 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.9 lib/parameters/instance_param.rb
parameters-0.1.8 lib/parameters/instance_param.rb