Class: ASE::Palette

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ase/palette.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Palette

Returns a new instance of Palette.



7
8
9
10
# File 'lib/ase/palette.rb', line 7

def initialize(name)
  @name = name
  @colors = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



35
36
37
38
39
40
41
# File 'lib/ase/palette.rb', line 35

def method_missing(method, *args, &block)
  if @colors.has_key?(method.to_s)
    return @colors[method.to_s]
  end

  super
end

Instance Attribute Details

#colorsObject

Returns the value of attribute colors.



5
6
7
# File 'lib/ase/palette.rb', line 5

def colors
  @colors
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ase/palette.rb', line 5

def name
  @name
end

Instance Method Details

#[](i) ⇒ Object



22
23
24
# File 'lib/ase/palette.rb', line 22

def [](i)
  @colors[i]
end

#add(name, color) ⇒ Object Also known as: []=, add_color



12
13
14
# File 'lib/ase/palette.rb', line 12

def add(name, color)
  @colors[name] = color
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/ase/palette.rb', line 31

def each(&block)
  @colors.each(&block)
end

#lengthObject Also known as: size



26
27
28
# File 'lib/ase/palette.rb', line 26

def length
  @colors.length
end

#remove(name) ⇒ Object



18
19
20
# File 'lib/ase/palette.rb', line 18

def remove(name)
  @colors.delete(name)
end