Module: TextTube::CoreExtensions
Overview
Core lib extensions reside here.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#to_constant ⇒ Object
to_constant tries to find a declared constant with the name specified in the string.
Instance Method Details
#blank? ⇒ Boolean
6 7 8 9 10 |
# File 'lib/ext/blank.rb', line 6 def blank? respond_to?(:empty?) ? empty? : !self end |
#to_constant ⇒ Object
to_constant tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.
Examples
"Module".to_constant #=> Module
"Class".to_constant #=> Class
12 13 14 15 16 17 18 |
# File 'lib/ext/to_constant.rb', line 12 def to_constant unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self fail NameError, "#{self.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |