class Module
Public Instance Methods
deconstantize()
click to toggle source
# File lib/ruby_us/extensions/module.rb, line 11 def deconstantize ancestor = ancestors.first splitted_trail = ancestor.to_s.split("::") trail_name = splitted_trail.slice(0, splitted_trail.length - 1).join("::") const_get(trail_name) if !trail_name.empty? && self.to_s != trail_name end
defines?(constant, verbose=false)
click to toggle source
# File lib/ruby_us/extensions/module.rb, line 19 def defines? constant, verbose=false splitted_trail = constant.split("::") trail_name = splitted_trail.first # try begin trail = const_get(trail_name) if Object.send(:const_defined?, trail_name) splitted_trail.slice(1, splitted_trail.length - 1).each do |constant_name| trail = trail.send(:const_defined?, constant_name) ? trail.const_get(constant_name) : nil end true if trail # catch (e) rescue Exception => e $stderr.puts "Exception recovered when trying to check if the constant \"#{constant}\" is defined: #{e}" if verbose end unless constant.empty? end
has_constants?()
click to toggle source
# File lib/ruby_us/extensions/module.rb, line 37 def has_constants? true if constants.any? end
Private Instance Methods
demodulize()
click to toggle source
# File lib/ruby_us/extensions/module.rb, line 3 def demodulize splitted_trail = self.to_s.split("::") constant = splitted_trail.last const_get constant if defines?(constant) end