Class: Playbook::Tokens::ColorHash

Inherits:
Object
  • Object
show all
Defined in:
lib/playbook/tokens.rb

Overview

Hash wrapper supporting colors and colors.key

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ColorHash

Returns a new instance of ColorHash.



57
58
59
# File 'lib/playbook/tokens.rb', line 57

def initialize(hash)
  @hash = hash.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/playbook/tokens.rb', line 65

def method_missing(method_name, *args, &block)
  key = method_name.to_sym
  if @hash.key?(key)
    @hash[key]
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



61
62
63
# File 'lib/playbook/tokens.rb', line 61

def [](key)
  @hash[key.to_sym]
end

#key?(key) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


92
93
94
# File 'lib/playbook/tokens.rb', line 92

def key?(key)
  @hash.key?(key.to_sym)
end

#keysObject



84
85
86
# File 'lib/playbook/tokens.rb', line 84

def keys
  @hash.keys
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/playbook/tokens.rb', line 74

def respond_to_missing?(method_name, include_private = false)
  @hash.key?(method_name.to_sym) || super
end

#to_hObject Also known as: to_hash



78
79
80
# File 'lib/playbook/tokens.rb', line 78

def to_h
  @hash
end

#valuesObject



88
89
90
# File 'lib/playbook/tokens.rb', line 88

def values
  @hash.values
end