Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b4dacd6ef4
Fetching contributors…

Cannot retrieve contributors at this time

74 lines (45 sloc) 1.429 kb

instancevalue

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

Installation

gem install instancevalue

Links

code

github.com/kachick/instancevalue

issues

github.com/kachick/instancevalue/issues

CI

travis-ci.org/#!/kachick/instancevalue

gem

rubygems.org/gems/instancevalue

gem+

metagem.info/gems/instancevalue

License

The MIT X License

Copyright © 2012 Kenichi Kamiya

See MIT-LICENSE for further details.

Jump to Line
Something went wrong with that request. Please try again.