From 2aff2bb01bd08872247785bca63b72a26fa60159 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 03:35:33 -0700 Subject: Improve and clean up load_module. --- dinobot.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'dinobot.rb') diff --git a/dinobot.rb b/dinobot.rb index 02c2184..947dfcd 100644 --- a/dinobot.rb +++ b/dinobot.rb @@ -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 -- cgit v1.2.3-70-g09d2