Module: ShatteredSupport::CoreExtensions::String::Inflections

Included in:
String
Defined in:
lib/shattered_support/core_ext/string/inflections.rb

Overview

Makes it possible to do “posts”.singularize that returns “post” and “MegaCoolClass”.underscore that returns “mega_cool_class”.

Instance Method Summary collapse

Instance Method Details

#camelize(first_letter = :upper) ⇒ Object Also known as: camelcase



15
16
17
18
19
20
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 15

def camelize(first_letter = :upper)
  case first_letter
    when :upper then Inflector.camelize(self, true)
    when :lower then Inflector.camelize(self, false)
  end
end

#classifyObject



44
45
46
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 44

def classify
  Inflector.classify(self)
end

#constantizeObject



58
59
60
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 58

def constantize
  Inflector.constantize(self)
end

#dasherizeObject



32
33
34
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 32

def dasherize
  Inflector.dasherize(self)
end

#demodulizeObject



36
37
38
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 36

def demodulize
  Inflector.demodulize(self)
end

#foreign_key(separate_class_name_and_id_with_underscore = true) ⇒ Object



54
55
56
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 54

def foreign_key(separate_class_name_and_id_with_underscore = true)
  Inflector.foreign_key(self, separate_class_name_and_id_with_underscore)
end

#humanizeObject

Capitalizes the first word and turns underscores into spaces and strips _id, so “employee_salary” becomes “Employee salary” and “author_id” becomes “Author”.



50
51
52
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 50

def humanize
  Inflector.humanize(self)
end

#pluralizeObject



7
8
9
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 7

def pluralize
  Inflector.pluralize(self)
end

#singularizeObject



11
12
13
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 11

def singularize
  Inflector.singularize(self)
end

#tableizeObject



40
41
42
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 40

def tableize
  Inflector.tableize(self)
end

#titleizeObject Also known as: titlecase



23
24
25
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 23

def titleize
  Inflector.titleize(self)
end

#underscoreObject



28
29
30
# File 'lib/shattered_support/core_ext/string/inflections.rb', line 28

def underscore
  Inflector.underscore(self)
end