Module: Moleculer::Support::StringUtil
Overview
A module of functional methods for working with strings.
Instance Method Summary collapse
-
#camelize(term) ⇒ Object
Converts a string to lowerCamelCase.
-
#underscore(term) ⇒ Object
Makes an underscored, lowercase form from the expression in the string.
Instance Method Details
#camelize(term) ⇒ Object
Converts a string to lowerCamelCase.
11 12 13 14 |
# File 'lib/moleculer/support/string_util.rb', line 11 def camelize(term) new_term = term.gsub(/(?:^|_)([a-z])/) { $1.upcase } new_term[0..1].downcase + new_term[2..-1] end |
#underscore(term) ⇒ Object
Makes an underscored, lowercase form from the expression in the string.
20 21 22 |
# File 'lib/moleculer/support/string_util.rb', line 20 def underscore(term) term.gsub(/(?<!^)[A-Z]/) { "_#$&" }.downcase end |