Module: RichEngine::Enum::Mixin

Defined in:
lib/rich_engine/enum/mixin.rb

Overview

Adds enum support to a class. Include it, then declare enums with ClassMethods#enum to get a class-level enum accessor and an instance-level reader that resolves the instance variable into an Value.

Examples:

class Player
  include RichEngine::Enum::Mixin
  enum :state, {idle: 0, running: 1, paused: 2}

  def initialize
    @state = :idle
  end
end

Player.states          #=> RichEngine::Enum
Player.new.state.idle? #=> true

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Extends the including class with ClassMethods.

Parameters:

  • base (Class)

    the class including this module



25
26
27
# File 'lib/rich_engine/enum/mixin.rb', line 25

def self.included(base)
  base.extend ClassMethods
end