Class: Mosespa::Puts

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

Instance Method Summary collapse

Constructor Details

#initializePuts

Returns a new instance of Puts.



91
92
93
94
95
96
97
# File 'lib/mosespa.rb', line 91

def initialize()
  @colors = Hash.new
  @available_colors = Queue.new
  String.colors
  .select{ |c| not [:black, :light_black, :white].include? c}
  .each { |c| @available_colors.push c }
end

Instance Method Details

#puts(author, text) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/mosespa.rb', line 99

def puts(author, text)
  unless @colors.has_key? author
    a_color = @available_colors.pop
    @colors[author] = a_color
  end
  c = @colors[author]
  author = author.colorize( c )
  $stdout.puts "#{author}: #{text}"
end