Class: String
Overview
:nodoc:
Instance Method Summary collapse
- #right_blank? ⇒ Boolean
- #right_camelize ⇒ Object
-
#right_constantize ⇒ Object
Constantize tries to find a declared constant with the name specified in the string.
Instance Method Details
#right_blank? ⇒ Boolean
100 101 102 |
# File 'lib/support.rb', line 100 def right_blank? empty? || strip.empty? end |
#right_camelize ⇒ Object
45 46 47 |
# File 'lib/support.rb', line 45 def right_camelize() self.dup.split(/_/).map{ |word| word.capitalize }.join('') end |
#right_constantize ⇒ Object
Constantize 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".constantize #=> Module
"Class".constantize #=> Class
38 39 40 41 42 43 |
# File 'lib/support.rb', line 38 def right_constantize() unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self raise NameError, "#{self.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |