diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 03:35:33 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 03:35:33 -0700 |
commit | 2aff2bb01bd08872247785bca63b72a26fa60159 (patch) | |
tree | 6432456b7119c9349ed63a799a00d1509185e8c4 /dinobot.rb | |
parent | acc8aebe98593e3e0ea6938fe2c3512472c0da91 (diff) | |
download | dinobot-2aff2bb01bd08872247785bca63b72a26fa60159.tar.gz dinobot-2aff2bb01bd08872247785bca63b72a26fa60159.tar.xz |
Improve and clean up load_module.
Diffstat (limited to 'dinobot.rb')
-rw-r--r-- | dinobot.rb | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -107,14 +107,24 @@ module Dinobot end def load_module(mod) - file = Dir.entries(File.dirname(__FILE__)).find { |x| x == mod.to_s.downcase + ".rb" } + mod = mod.downcase + puts "== Loading module: #{mod}." - if file - puts "== Loading #{mod}." + file = Dir.entries(File.dirname(__FILE__)) + .find { |x| x == mod.to_s + ".rb" } - load file - @modules[mod.downcase] = eval("Dinobot::#{mod}").new + unless file + puts "== Failed to load module: #{mod} (File #{mod}.rb not found)." + + return false end + + load file + + m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod }) + @modules[mod] = m.new + + puts "== Loaded module: #{mod} (#{m})." end end end |