class ClasslessMud::Commands::Commands

This is the commands command. The naming is weird, but this lists out all available commands

Constants

COMMANDS_TO_HIDE

Public Class Methods

columnize(array, width=4) click to toggle source
# File lib/classless_mud/commands/commands.rb, line 20
def self.columnize array, width=4
  result = ''
  longest_char = array.max_by(&:size).size
  array.each_slice(width) do |row|
    spaced_rows = row.map { |word| "%#{longest_char}s" % word }
    result += spaced_rows.join(" ") + "\n"
  end
  result
end
commands() click to toggle source
# File lib/classless_mud/commands/commands.rb, line 9
def self.commands
  ClasslessMud::Commands.constants
     .select { |c| Class === ClasslessMud::Commands.const_get(c) }
     .reject { |c| COMMANDS_TO_HIDE.include?(ClasslessMud::Commands.const_get(c)) }
     .map { |c| c.to_s.downcase }
end
perform(game, player, message) click to toggle source
# File lib/classless_mud/commands/commands.rb, line 16
def self.perform game, player, message
  player.puts columnize(commands)
end