aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 04:16:38 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 04:16:38 -0700
commitd920b5654e30ed10caf56bab6198fbd99fecd12d (patch)
tree7832fd7247b8a0dd3c2ef4542fd7e4cf00e34862
parentb507db60c3901ee81a879114982342cddecde017 (diff)
downloaddinobot-d920b5654e30ed10caf56bab6198fbd99fecd12d.tar.gz
dinobot-d920b5654e30ed10caf56bab6198fbd99fecd12d.tar.xz
Add unload_module method.
-rw-r--r--dinobot.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 866396e..f5ea364 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -123,5 +123,22 @@ module Dinobot
puts "== Failed to load module: #{mod} (#{e.message})"
end
end
+
+ def unload_module(mod)
+ mod = mod.downcase.intern
+ puts "== Unloading module: #{mod}"
+
+ unless @modules.has_key?(mod)
+ puts "== Failed to unload module: #{mod} (module not loaded)"
+ return
+ end
+
+ @modules.delete(mod)
+
+ Dinobot.send(
+ :remove_const,
+ Dinobot.constants.find { |x| x.downcase == mod }
+ )
+ end
end
end