123456789_123456789_123456789_123456789_123456789_

Class: IRB::ExtendCommand::ShowCmds

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Nop
Instance Chain:
self, Nop
Inherits: IRB::ExtendCommand::Nop
Defined in: lib/irb/cmd/show_cmds.rb

Class Method Summary

Nop - Inherited

.category, .description,
.execute

See additional method definition at line 39.

.new, .string_literal?

Instance Attribute Summary

Nop - Inherited

Instance Method Summary

Constructor Details

This class inherits a constructor from IRB::ExtendCommand::Nop

Instance Method Details

#execute(*args)

[ GitHub ]

  
# File 'lib/irb/cmd/show_cmds.rb', line 14

def execute(*args)
  commands_info = IRB::ExtendCommandBundle.all_commands_info
  commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
  longest_cmd_name_length = commands_info.map { |c| c[:display_name] }.max { |a, b| a.length <=> b.length }.length

  output = StringIO.new

  commands_grouped_by_categories.each do |category, cmds|
    output.puts Color.colorize(category, [:BOLD])

    cmds.each do |cmd|
      output.puts "  #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)}    #{cmd[:description]}"
    end

    output.puts
  end

  puts output.string

  nil
end