Sha256: e388fb584669cd5e5cbb59e9803c6f422e906123577adcdb3a8942bd354332db

Contents?: true

Size: 354 Bytes

Versions: 4

Compression:

Stored size: 354 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

# Extensions for String

class String

  # convert to snake_case from CamelCase
  #
  #   'FooBar'.snake_case # => 'foo_bar'

  def snake_case
    gsub(/\B[A-Z]/, '_\&').downcase.gsub(' ', '_')
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ramaze-0.1.2 lib/ramaze/snippets/string/snake_case.rb
ramaze-0.1.3 lib/ramaze/snippets/string/snake_case.rb
ramaze-0.1.1 lib/ramaze/snippets/string/snake_case.rb
ramaze-0.1.4 lib/ramaze/snippets/string/snake_case.rb