lib/sugar-high/class_ext.rb in sugar-high-0.4.5.2 vs lib/sugar-high/class_ext.rb in sugar-high-0.4.6

- old
+ new

@@ -10,49 +10,56 @@ 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 end -module ClassExt +module ClassExt + def get_module name + # Module.const_get(name) + name.to_s.constantize + rescue + nil + end + def is_class?(clazz) clazz.is_a?(Class) && (clazz.respond_to? :new) end def is_module?(clazz) clazz.is_a?(Module) && !(clazz.respond_to? :new) end def class_exists?(name) - is_class? Module.const_get(name) - rescue NameError + is_class? get_module(name) + rescue return false end def module_exists?(name) - is_module? Module.const_get(name) + is_module? get_module(name) rescue NameError return false end def try_class name return name if name.kind_of?(Class) - found = Module.const_get(name) if name.kind_of_label? + found = get_module(name) if name.kind_of_label? return found if found.is_a?(Class) rescue false end def try_module name return name if name.kind_of?(Module) - found = Module.const_get(name) if name.kind_of_label? + found = get_module(name) if name.kind_of_label? return found if found.is_a?(Module) rescue false end def try_module_only name return name if is_module?(name) - found = Module.const_get(name) if name.kind_of_label? + found = get_module(name) if name.kind_of_label? return found if is_module?(found) rescue false end \ No newline at end of file