Module: Inflector
- Extended by:
- Inflector
- Included in:
- Inflector
- Defined in:
- lib/inflector.rb,
lib/inflector/core_ext/string.rb
Defined Under Namespace
Modules: CoreExtensions
Classes: Words
Instance Method Summary
collapse
Instance Method Details
#camelize(s) ⇒ Object
67
68
69
|
# File 'lib/inflector.rb', line 67
def camelize(s)
uncapitalize pascalize(s)
end
|
#constantize(s) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/inflector.rb', line 76
def constantize(s)
const = Object
s.split('::').each do |name|
const = const.const_get(name)
end
const
end
|
#pascalize(s) ⇒ Object
71
72
73
74
|
# File 'lib/inflector.rb', line 71
def pascalize(s)
return s if s !~ /_/ && s =~ /[A-Z]+.*/
s.split('_').map { |e| e.capitalize }.join
end
|
#pluralize(s) ⇒ Object
91
92
93
|
# File 'lib/inflector.rb', line 91
def pluralize(s)
inflect_word(s, words.plurals, words.write_plural_rules)
end
|
#singularize(s) ⇒ Object
95
96
97
|
# File 'lib/inflector.rb', line 95
def singularize(s)
inflect_word(s, words.singulars, words.write_singular_rules)
end
|
#uncapitalize(s) ⇒ Object
99
100
101
|
# File 'lib/inflector.rb', line 99
def uncapitalize(s)
s[0, 1].downcase + s[1..-1]
end
|
#underscore(s) ⇒ Object
85
86
87
88
89
|
# File 'lib/inflector.rb', line 85
def underscore(s)
return s.downcase if s =~ /^[A-Z]+$/
s.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
return $+.downcase
end
|
#words ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/inflector.rb', line 59
def words
if block_given?
yield Words.instance
else
Words.instance
end
end
|