lib/sugar-high/class_ext.rb in sugar-high-0.4.9.2 vs lib/sugar-high/class_ext.rb in sugar-high-0.4.9.3
- old
+ new
@@ -1,18 +1,32 @@
require 'sugar-high/kind_of'
require 'sugar-high/array'
-class Class
+class Module
def include_and_extend(the_module, options={})
options[:instance_methods] ||= :InstanceMethods
options[:class_methods] ||= :ClassMethods
# Mainly include but be flexible
main_module = const_get(the_module.to_s.to_sym)
include main_module # for an extend_and_include method, change this to extend main_module
include main_module.const_get(options[:instance_methods]) if main_module.const_defined?(options[:instance_methods])
extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods])
end
+
+ def autoload_modules *args
+
+ options = args.extract_options!
+ root = options[:root] || AutoLoader.root || ''
+ from = options[:from] || File.join(root, self.name.to_s.underscore)
+
+ # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
+ # It is very useful for situations of having not load_paths built Rails or Gems way.
+ args.each do |req_name|
+ send :autoload, req_name, "#{from}/#{req_name.to_s.underscore}"
+ end
+ end
+
end
module AutoLoader
@@root = ''
@@ -96,21 +110,5 @@
end
raise "Not one Module for any of: #{names} is currently loaded" if modules.empty?
modules.first
end
end
-
-class Object
- # Mixing this method to Object, so both modules and classes would be able to use it!
- def autoload_modules *args
-
- options = args.extract_options!
- root = options[:root] || AutoLoader.root || ''
- from = options[:from] || File.join(root, self.name.to_s.underscore)
-
- # Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
- # It is very useful for situations of having not load_paths built Rails or Gems way.
- args.each do |req_name|
- send :autoload, req_name, "#{from}/#{req_name.to_s.underscore}"
- end
- end
-end