Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/string_support.rb

Overview

support camerize and underscore

Instance Method Summary collapse

Instance Method Details

#camelizeObject



5
6
7
# File 'lib/fusuma/string_support.rb', line 5

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

#underscoreObject



9
10
11
12
13
14
15
# File 'lib/fusuma/string_support.rb', line 9

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