Class: String

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

Overview

Custom enhancements

Instance Method Summary collapse

Instance Method Details

#humanize(options = { capitalize: true }) ⇒ Object



11
12
13
14
15
# File 'lib/string_overrides.rb', line 11

def humanize(options = { capitalize: true })
  s = underscore.tr('_', ' ')
  s = s.capitalize if options[:capitalize]
  s
end

#underscoreObject



3
4
5
6
7
8
9
# File 'lib/string_overrides.rb', line 3

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