Module: Bandoleer::Conversions

Included in:
Bandoleer
Defined in:
lib/bandoleer/conversions.rb

Overview

Provides methods to convert various objects to usefully formatted Strings.

Instance Method Summary collapse

Instance Method Details

#klass_to_snakeString

Convert the klass name to a snake_cased String.

Returns:

  • (String)


15
16
17
# File 'lib/bandoleer/conversions.rb', line 15

def klass_to_snake
  name.split('::').last.split(/(?=[A-Z])/).join('_').downcase
end

#snake_to_camel(str) ⇒ String

Convert a String from snake_case to CamelCase.

Parameters:

  • str (String)

    String to convert

Returns:

  • (String)


9
10
11
# File 'lib/bandoleer/conversions.rb', line 9

def snake_to_camel( str )
  str.split('_').map(&:capitalize).join
end