Module: Arcanus::Utils
- Included in:
- Command::Base
- Defined in:
- lib/arcanus/utils.rb
Overview
A miscellaneous set of utility functions.
Class Method Summary collapse
-
.camel_case(string) ⇒ String
Converts a string containing underscores/hyphens/spaces into CamelCase.
-
.deep_dup(hash) ⇒ Hash
Returns a deep copy of the specified hash.
-
.snake_case(string) ⇒ String
Convert string containing camel case or spaces into snake case.
Class Method Details
.camel_case(string) ⇒ String
Converts a string containing underscores/hyphens/spaces into CamelCase.
10 11 12 13 14 |
# File 'lib/arcanus/utils.rb', line 10 def camel_case(string) string.split(/_|-| /) .map { |part| part.sub(/^\w/, &:upcase) } .join end |
.deep_dup(hash) ⇒ Hash
Returns a deep copy of the specified hash.
34 35 36 37 38 |
# File 'lib/arcanus/utils.rb', line 34 def deep_dup(hash) hash.each_with_object({}) do |(key, value), dup| dup[key] = value.is_a?(Hash) ? deep_dup(value) : value end end |
.snake_case(string) ⇒ String
Convert string containing camel case or spaces into snake case.
22 23 24 25 26 27 28 |
# File 'lib/arcanus/utils.rb', line 22 def snake_case(string) string.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |