Class: String

Inherits:
Object show all
Defined in:
lib/pup/utilities/string.rb

Instance Method Summary collapse

Instance Method Details

#sanitize_path!Object



14
15
16
17
# File 'lib/pup/utilities/string.rb', line 14

def sanitize_path!
  replace(self[0..-2]) if self[-1] == "/"
  replace("/" + self) if self[0] != "/"
end

#to_camelcaseObject



2
3
4
# File 'lib/pup/utilities/string.rb', line 2

def to_camelcase
  split("_").map(&:capitalize).join
end

#to_snakecaseObject



6
7
8
9
10
11
12
# File 'lib/pup/utilities/string.rb', line 6

def to_snakecase
  gsub(/::/, "/").
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
    gsub(/([a-z\d])([A-Z])/, '\1_\2').
    tr("-", "_").
    downcase
end