Sha256: 6f89000fad828d017ea7b2e92f22846449bb3c0540c2710d27438d846a3ae144

Contents?: true

Size: 315 Bytes

Versions: 23

Compression:

Stored size: 315 Bytes

Contents

class String
  def to_snake_case
    self.gsub(/::/, '/')
      .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      .gsub(/([a-z\d])([A-Z])/, '\1_\2')
      .tr('-', '_')
      .downcase
  end

  def to_camel_case
    return self if self !~ /_/ && self =~ /[A-Z]+.*/
    split('_').map { |e| e.capitalize }.join
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
awspec-0.1.0 lib/awspec/ext/string.rb
awspec-0.0.2 lib/awspec/ext/string.rb
awspec-0.0.1 lib/awspec/ext/string.rb