Loading code at runtime in Ruby

Topics: Ruby

This note shows a Ruby example of loading command modules at runtime for a Discord bot.

Example from Writing a Discord Bot in Ruby using DiscordRB:

module DiscordCommands; end
Dir['src/modules/commands/*.rb'].each { |mod| load mod }
DiscordCommands.constants.each do |mod|
  BOT.include! DiscordCommands.const_get mod
end