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
-
#klass_to_snake ⇒ String
Convert the klass name to a snake_cased String.
-
#snake_to_camel(str) ⇒ String
Convert a String from snake_case to CamelCase.
Instance Method Details
#klass_to_snake ⇒ String
Convert the klass name to a snake_cased 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.
9 10 11 |
# File 'lib/bandoleer/conversions.rb', line 9 def snake_to_camel( str ) str.split('_').map(&:capitalize).join end |