Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/swift_tools/core_ext.rb
Instance Method Summary collapse
- #camelcase(*separators) ⇒ Object
- #lower_camelcase(*separators) ⇒ Object
- #upper_camelcase(*separators) ⇒ Object
Instance Method Details
#camelcase(*separators) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/swift_tools/core_ext.rb', line 2 def camelcase(*separators) case separators.first when Symbol, TrueClass, FalseClass, NilClass first_letter = separators.shift end separators = ['_'] if separators.empty? str = self.dup separators.each do |s| str = str.gsub(/(?:#{s}+)([a-z])/){ $1.upcase } end case first_letter when :upper, true str = str.gsub(/(\A|\s)([a-z])/){ $1 + $2.upcase } when :lower, false str = str.gsub(/(\A|\s)([A-Z])/){ $1 + $2.downcase } end str end |
#lower_camelcase(*separators) ⇒ Object
30 31 32 |
# File 'lib/swift_tools/core_ext.rb', line 30 def lower_camelcase(*separators) camelcase(:lower, *separators) end |
#upper_camelcase(*separators) ⇒ Object
26 27 28 |
# File 'lib/swift_tools/core_ext.rb', line 26 def upper_camelcase(*separators) camelcase(:upper, *separators) end |