Sha256: 9f700102139bf938a918e500a2b37372b3030eedd0a7ce5cdcf69d7b94bba213
Contents?: true
Size: 1.02 KB
Versions: 4
Compression:
Stored size: 1.02 KB
Contents
module BubbleWrap # This module contains simplified version of the `camelize` and # `underscore` methods from ActiveSupport, since these are such # common operations when dealing with the Cocoa API. module String # Convert 'snake_case' into 'CamelCase' def camelize(uppercase_first_letter = true) string = self.dup string.gsub!(/(?:_|(\/))([a-z\d]*)/i) do new_word = $2.downcase new_word[0] = new_word[0].upcase new_word = "/#{new_word}" if $1 == '/' new_word end if uppercase_first_letter string[0] = string[0].upcase else string[0] = string[0].downcase end string.gsub!('/', '::') string end # Convert 'CamelCase' into 'snake_case' def underscore word = self.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end end end String.send(:include, BubbleWrap::String)
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
bubble-wrap-1.0.0 | motion/core/string.rb |
bubble-wrap-1.0.0.pre.2 | motion/core/string.rb |
bubble-wrap-1.0.0.pre | motion/core/string.rb |
bubble-wrap-0.4.0 | motion/core/string.rb |