Class: String
- Defined in:
- lib/support/active_support_lite/blank.rb,
lib/support/active_support_lite/string.rb
Overview
:nodoc:all
Instance Method Summary collapse
-
#blank? ⇒ Boolean
:nodoc.
-
#camelize(first_letter_in_uppercase = true) ⇒ Object
:nodoc.
-
#classify ⇒ Object
:nodoc.
-
#constantize ⇒ Object
:nodoc.
-
#demodulize ⇒ Object
:nodoc.
-
#underscore ⇒ Object
:nodoc.
Instance Method Details
#blank? ⇒ Boolean
:nodoc
57 58 59 |
# File 'lib/support/active_support_lite/blank.rb', line 57 def blank? self !~ /\S/ end |
#camelize(first_letter_in_uppercase = true) ⇒ Object
:nodoc
30 31 32 33 34 35 36 |
# File 'lib/support/active_support_lite/string.rb', line 30 def camelize( first_letter_in_uppercase = true) if first_letter_in_uppercase gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } else first + camelize(lower_case_and_underscored_word)[1..-1] end end |
#classify ⇒ Object
:nodoc
25 26 27 |
# File 'lib/support/active_support_lite/string.rb', line 25 def classify # DOES NOT SINGULARISE camelize(self.sub(/.*\./, '')) end |
#constantize ⇒ Object
:nodoc
17 18 19 20 21 22 |
# File 'lib/support/active_support_lite/string.rb', line 17 def constantize unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self raise NameError, "#{self} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |
#demodulize ⇒ Object
:nodoc
12 13 14 |
# File 'lib/support/active_support_lite/string.rb', line 12 def demodulize gsub(/^.*::/, '') end |
#underscore ⇒ Object
:nodoc
3 4 5 6 7 8 9 |
# File 'lib/support/active_support_lite/string.rb', line 3 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |