Class: Tibber::Enum

Inherits:
Object
  • Object
show all
Defined in:
lib/tibber/const.rb

Overview

The ‘Enum` class provides a way to define constant-based enumerations dynamically.

Direct Known Subclasses

Avatar, HomeType, Resolution, Screens

Class Method Summary collapse

Class Method Details

.enum(array) ⇒ Object

Defines constants from an array of symbols or strings.

The above example dynamically defines constants ‘RED`, `GREEN`, and `BLUE` inside the `Colors` class.

Examples:

class Colors < Enum
  enum %w[RED GREEN BLUE]
end

Colors::RED   # => "RED"
Colors::GREEN # => "GREEN"

Parameters:

  • array (Array<Symbol, String>)

    List of values to be set as constants.



18
19
20
21
22
# File 'lib/tibber/const.rb', line 18

def self.enum(array)
  array.each do |cnst|
    const_set cnst, cnst
  end
end