Module: Moleculer::Support::StringUtil

Extended by:
StringUtil
Included in:
StringUtil
Defined in:
lib/moleculer/support/string_util.rb

Overview

A module of functional methods for working with strings.

Instance Method Summary collapse

Instance Method Details

#camelize(term) ⇒ Object

Converts a string to lowerCamelCase.

Parameters:

  • term (String)

    the term to convert



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.

Parameters:

  • term (String)

    the word to convert into an underscored string



20
21
22
# File 'lib/moleculer/support/string_util.rb', line 20

def underscore(term)
  term.gsub(/(?<!^)[A-Z]/) { "_#$&" }.downcase
end