Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Constant values for each instance.

tree: d22eddfd90

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 lib
Octocat-spinner-32 History.rdoc
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 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 - val(: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.