Sha256: eb21060fd6d52918a1b342f6e441c739f572e4f2dfc332e6c97feb814c8b9f60

Contents?: true

Size: 579 Bytes

Versions: 2

Compression:

Stored size: 579 Bytes

Contents

# Extend the Ruby String class
class String
  ##
  # Returns the snake_case version of a word
  #
  # Example:
  #
  #   "IndexController".snake_case = "index_controller"
  def snake_case
    gsub!(/::/, '/')
    gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    gsub!(/([a-z\d])([A-Z])/, '\1_\2')
    tr!('-', '_')
    downcase!
    self
  end

  ##
  # Returns the CamelCase version of a word
  #
  # Example:
  #   "index_controller".camel_case = "IndexController"
  def camel_case
    return self if self !~ /_/ && self =~ /[A-Z]+.*/
    split('_').map(&:capitalize).join
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rapid_runty-0.1.4 lib/rapid_runty/util.rb
rapid_runty-0.1.3 lib/rapid_runty/util.rb