No commit activity in last 3 years
No release in over 3 years
Gem adds class methods to create readable, writable and accessible constants.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

EasyClassConstants

Gem adds class methods to create readable, writable and accessible constants.

Installation

Add this line to your application's Gemfile:

gem 'easy_class_constants'

And then execute:

$ bundle

Or install it yourself as:

$ gem install easy_class_constants

Usage

Adding constants to your class is easy:

class ECCObject
  include EasyClassConstants

  readable_constant :read_only, 'R'
  writable_constant :write_only, 'W'
  accessible_constant :read_write, 'RW'
  hash_indexed_by_readable_constants(:mapping, [[:internal_error, 0, 'Internal Error - Try Again Later'],
                                          [:network_error, 1, 'Network Error - Check With Your Admin']])

  hash_indexed_by_readable_constants(:simple_mapping, [[:HELLO_WORLD, 'Hello World'],
                                          [:HELLO_KITTY, 'Hello Kitty']])
                                  
end

Then you can call:

ECCTestObject.INTERNAL_ERROR                 #will return 0
ECCTestObject.SIMPLE_MAPPING[:HELLO_KITTY]   # will return 'Hello Kitty'
ECCTestObject.SIMPLE_MAPPING.HELLO_KITTY     # will return 'Hello Kitty'
ECCTestObject.READ_WRITE                     # will return 'RW'

Credits

Oha_extensions is maintained by Bookrenter/Rafter and is funded by BookRenter.com.

BookRenter.com Logo

Copyright

Copyright (c) 2012 Bookrenter.com. See LICENSE.txt for further details.