erector/erector · tag.rb
ruby logo
def snake_case(s)
      if s.match(/\A[A-Z]+\z/)
        s.downcase
      else
        s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
         gsub(/([a-z])([A-Z])/, '\1_\2').
         downcase
      end
    end
Similar code snippets
1.
axsh/isono · util.rb
Match rating: 80.09% · See similar code snippets
ruby logo
def snake_case(str)
      return str.downcase if str.match(/\A[A-Z]+\z/)
      str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
        gsub(/([a-z])([A-Z])/, '\1_\2').
        downcase
    end
2.
andymeneely/squib · data_frame.rb
Match rating: 72.44% · See similar code snippets
ruby logo
def snake_case(str)
      str.to_s.
          strip.
          gsub(/\s+/,'_').
          gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z]+)([A-Z])/,'\1_\2').
          downcase.
          to_sym
    end
3.
mollie/mollie-api-ruby · util.rb
Match rating: 60.6% · See similar code snippets
ruby logo
def underscore(string)
      string.to_s.gsub(/::/, '/')
            .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            .gsub(/([a-z\d])([A-Z])/, '\1_\2')
            .tr('-', '_')
            .downcase.to_s
    end
4.
shioyama/mobility · util.rb
Match rating: 58.66% · See similar code snippets
ruby logo
def underscore(str)
      call_or_yield str do
        str.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
      end
    end
5.
nesquena/backburner · helpers.rb
Match rating: 57.82% · See similar code snippets
ruby logo
def dasherize(word)
      classify(word).to_s.gsub(/::/, '/').
            gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
            gsub(/([a-z\d])([A-Z])/,'\1_\2').
            tr("_", "-").downcase
    end
6.
zerowidth/camper_van · utils.rb
Match rating: 57.17% · See similar code snippets
ruby logo
def irc_name(name)
      name.gsub('/', '-').
        gsub(/\W/, ' ').
        gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
        gsub(/([a-z\d])([A-Z])/,'\1_\2').
        gsub(/\s+/, "_").
        tr("-", "_").
        downcase
    end
7.
david942j/memory_io · util.rb
Match rating: 52.77% · See similar code snippets
ruby logo
def underscore(str)
      return '' if str.empty?

      str = str.gsub('::', '/')
      str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
      str.downcase!
      str
    end
8.
bemurphy/motivation · motivation.rb
Match rating: 50.65% · See similar code snippets
ruby logo
def translation_key
      key = name.gsub(/Motivation\z/, '')
      key.gsub!(/^.*::/, '')
      key.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
      key.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
      key.tr!("-", "_")
      key.downcase!
    end
9.
stratumn/agent-client-ruby · helper.rb
Match rating: 48.07% · See similar code snippets
ruby logo
def underscore(string)
      word = string.to_s.dup
      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
10.
mhuggins/a2z · helpers.rb
Match rating: 47.99% · See similar code snippets
ruby logo
def underscore(camel_cased_word)
      camel_cased_word.dup.tap do |word|
        word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
        word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
        word.tr!('-', '_')
        word.downcase!
      end
    end