Class: Mosespa::Puts

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

Instance Method Summary collapse

Constructor Details

#initialize(colorize) ⇒ Puts

Returns a new instance of Puts.



88
89
90
91
92
93
94
95
# File 'lib/m.rb', line 88

def initialize(colorize)
  @colorize = colorize
  @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



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

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