Sha256: e61b299dd5f96197d3cb53543592760f8b83368394026126947f7828f6c76c2f
Contents?: true
Size: 723 Bytes
Versions: 2
Compression:
Stored size: 723 Bytes
Contents
module Pico module StringInflections refine String do def to_camel_case str = "_#{self}" str.gsub!(%r{_[a-z]}) { |snake| snake.slice(1).upcase } str.gsub!('/', '::') str end def to_snake_case str = gsub '::', '/' # Convert FOOBar => FooBar str.gsub! %r{[[:upper:]]{2,}} do |uppercase| bit = uppercase[0] bit << uppercase[1...-1].downcase bit << uppercase[-1] bit end str.gsub! %r{[[:lower:]][[:upper:]]+[[:lower:]]} do |camel| bit = camel[0] bit << '_' bit << camel[1..-1].downcase end str.downcase! str end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pico-0.1.0 | lib/pico/string_inflections.rb |
pico-0.0.1 | lib/pico/string_inflections.rb |