Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/under_os/core/string.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #camelize ⇒ Object
- #capitalize ⇒ Object
- #constantize ⇒ Object
- #dasherize ⇒ Object
- #ends_with?(substr) ⇒ Boolean
- #starts_with?(substr) ⇒ Boolean
- #underscore ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
26 27 28 |
# File 'lib/under_os/core/string.rb', line 26 def blank? self !~ /[^[:space:]]/ end |
#camelize ⇒ Object
6 7 8 |
# File 'lib/under_os/core/string.rb', line 6 def camelize gsub(/(\-|_)+([a-z])?/){|m| $2 ? $2.upcase : ''} end |
#capitalize ⇒ Object
14 15 16 |
# File 'lib/under_os/core/string.rb', line 14 def capitalize self[0].upcase + slice(1, size) end |
#constantize ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/under_os/core/string.rb', line 30 def constantize names = self.split('::') names.shift if names.empty? || names.first.empty? constant = Object names.each do |name| constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) end constant end |
#dasherize ⇒ Object
10 11 12 |
# File 'lib/under_os/core/string.rb', line 10 def dasherize underscore.gsub('_', '-') end |
#ends_with?(substr) ⇒ Boolean
22 23 24 |
# File 'lib/under_os/core/string.rb', line 22 def ends_with?(substr) rindex(substr) == size - substr.size end |
#starts_with?(substr) ⇒ Boolean
18 19 20 |
# File 'lib/under_os/core/string.rb', line 18 def starts_with?(substr) index(substr) == 0 end |
#underscore ⇒ Object
2 3 4 |
# File 'lib/under_os/core/string.rb', line 2 def underscore gsub(/([a-z\d])([A-Z]+)/, '\1_\2').gsub('-', '_').downcase end |