Class: ASE::Palette

Inherits:
Object
  • Object
show all
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.



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

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



29
30
31
32
33
34
35
# File 'lib/ase/palette.rb', line 29

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.



3
4
5
# File 'lib/ase/palette.rb', line 3

def colors
  @colors
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ase/palette.rb', line 3

def name
  @name
end

Instance Method Details

#[](i) ⇒ Object



20
21
22
# File 'lib/ase/palette.rb', line 20

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

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



10
11
12
# File 'lib/ase/palette.rb', line 10

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

#lengthObject Also known as: size



24
25
26
# File 'lib/ase/palette.rb', line 24

def length
  @colors.length
end

#remove(name) ⇒ Object



16
17
18
# File 'lib/ase/palette.rb', line 16

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