Module: Enumish

Included in:
StbKeys
Defined in:
lib/mixins/enumish.rb

Overview

The Enum module provides a more traditional-looking enum object. Note that the common Ruby idiom for enums is to declare constants in a module, which can be accessed like this: Fruits::BANANA

Instance Method Summary collapse

Instance Method Details

#enum(hash = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/mixins/enumish.rb', line 6

def enum(hash={})
  @enum ||= {}
  @enum.update(hash)
  hash.each do |k,v|
    self.class.send(:attr_reader, k)
    self.instance_variable_set("@#{k}".to_sym, v)
  end
end