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.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 .yardopts
Octocat-spinner-32 Gemfile
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 instancevalue.gemspec
README.md

instancevalue

Build Status Gem Version

Description

Constant values for each instance.

Features

instance_variable like API

  • .value_reader
  • #instance_value_defined?
  • #instance_value_get
  • #instance_value_set
  • #instance_values
  • #remove_instance_value

Aliased shortname

  • #val

Usage

require 'instancevalue'

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

Requirements

Install

$ gem install instancevalue

Link

License

The MIT X11 License
Copyright (c) 2012 Kenichi Kamiya
See MIT-LICENSE for further details.

Something went wrong with that request. Please try again.