Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ruby-bindgen/refinements/string.rb
Instance Method Summary collapse
-
#camelize ⇒ Object
Taken from ActiveSupport with modifications.
-
#underscore ⇒ Object
Taken from ActiveSupport with modifications.
-
#upcase_first ⇒ Object
Taken from ActiveSupport with modifications.
Instance Method Details
#camelize ⇒ Object
Taken from ActiveSupport with modifications
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby-bindgen/refinements/string.rb', line 12 def camelize() if self.match?(/\A[a-z\d]*\z/) return self.capitalize end return self if self.match?(/\A[A-Z]+\z/) input = self.match?(/\A[A-Z_0-9]*\z/) ? self.downcase : self string = input.sub(/^[a-z\d]*/) { |match| match.capitalize! || match } string.gsub!(/\/, ::/) string.gsub!(/(?:_|-|\.|::|,| |\<|\>|(\/))([a-z\d]*)/i) do word = $2 word[0] = word[0].capitalize || word[0] unless word.empty? $1 ? "::#{word}" : word end string end |
#underscore ⇒ Object
Taken from ActiveSupport with modifications
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-bindgen/refinements/string.rb', line 31 def underscore return self unless /[A-Z-]|::/.match?(self) word = self.gsub("::".freeze, "/".freeze) word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze) word.gsub!(/([a-z])([A-Z])/, '\1_\2'.freeze) word.gsub!(/([a-z])(\d+[A-Z])/, '\1_\2'.freeze) word.tr!("-".freeze, "_".freeze) word.downcase! word end |
#upcase_first ⇒ Object
Taken from ActiveSupport with modifications
3 4 5 6 7 8 9 |
# File 'lib/ruby-bindgen/refinements/string.rb', line 3 def upcase_first if self.length > 0 self[0].upcase.concat(self[1..-1]) else self end end |