Module: Shirinji::Utils::String
- Defined in:
- lib/shirinji/utils/string.rb
Constant Summary collapse
- CAMEL =
/[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/
Class Method Summary collapse
Class Method Details
.camelcase(str) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/shirinji/utils/string.rb', line 9 def camelcase(str) chunks = str.to_s.split('_').map do |w| w = w.downcase w[0] = w[0].upcase w end chunks.join end |
.snakecase(str) ⇒ Object
19 20 21 |
# File 'lib/shirinji/utils/string.rb', line 19 def snakecase(str) str.gsub(CAMEL) { |s| s.split('').join('_') }.downcase end |