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.



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

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



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

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