Class: Mir::Rgb

Inherits:
Object
  • Object
show all
Defined in:
lib/mir/01_model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, g, b) ⇒ Rgb

Returns a new instance of Rgb.



17
18
19
# File 'lib/mir/01_model.rb', line 17

def initialize r,g,b
  @r,@g,@b=r,g,b
end

Instance Attribute Details

#bObject

Returns the value of attribute b.



16
17
18
# File 'lib/mir/01_model.rb', line 16

def b
  @b
end

#gObject

Returns the value of attribute g.



16
17
18
# File 'lib/mir/01_model.rb', line 16

def g
  @g
end

#rObject

Returns the value of attribute r.



16
17
18
# File 'lib/mir/01_model.rb', line 16

def r
  @r
end

Class Method Details

.randomObject



29
30
31
# File 'lib/mir/01_model.rb', line 29

def self.random
  Rgb.new rand(255),rand(255),rand(255)
end

Instance Method Details

#to_aObject



21
22
23
# File 'lib/mir/01_model.rb', line 21

def to_a
  [self.r,self.g,self.b]
end

#to_sObject



25
26
27
# File 'lib/mir/01_model.rb', line 25

def to_s
  "(#{r.to_s.rjust(3)},#{g.to_s.rjust(3)},#{b.to_s.rjust(3)})"
end