Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Constant values for each instance.
Ruby
tree: 5376ececb2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
lib
test
History.rdoc
LICENSE
Manifest.txt
README.rdoc
Rakefile

README.rdoc

Instance Value

Description

Set constant values for each instance.

Usage

  • setup

    require 'instancevalue'
  • overview

    class Person
      include InstanceValue
    
      value_reader :birthday
    
      def initialize(birthday)
        val :birthday, birthday
      end
    
      def age
        (Time.now - birthday) / (60 * 60 * 24 * 365)
      end
    end
    
    person = Person.new Time.at YOUR_BIRTHDAY
    person.birthday                                 #=> YOUR_BIRTHDAY
    person.age                                      #=> age at runtime
    person.instance_eval{val :birthday, Time.now}   #=> Exception
  • It has instance_variable like API:

    • .value_reader

    • #instance_value_defined?

    • #instance_value_get

    • #instance_value_set

    • #instance_values

    • #remove_instance_value

  • Aliased shortname:

    • #val

Requirements

  • Ruby 1.9.2 or later

    target release versions

    • 1.9.3-p125

    • 1.9.2-p290

Installation

  • gem install instancevalue

License

Copyright (C) 2012 Kenichi Kamiya

The MIT/X11 License (See the file LICENSE)

Something went wrong with that request. Please try again.