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.10.1 lib/awspec/ext/string.rb
awspec-0.10.0 lib/awspec/ext/string.rb
awspec-0.9.0 lib/awspec/ext/string.rb
awspec-0.8.1 lib/awspec/ext/string.rb
awspec-0.8.0 lib/awspec/ext/string.rb
awspec-0.7.0 lib/awspec/ext/string.rb
awspec-0.6.4 lib/awspec/ext/string.rb
awspec-0.6.3 lib/awspec/ext/string.rb
awspec-0.6.2 lib/awspec/ext/string.rb
awspec-0.6.1 lib/awspec/ext/string.rb
awspec-0.6.0 lib/awspec/ext/string.rb
awspec-0.5.0 lib/awspec/ext/string.rb
awspec-0.4.1 lib/awspec/ext/string.rb
awspec-0.4.0 lib/awspec/ext/string.rb
awspec-0.3.0 lib/awspec/ext/string.rb
awspec-0.2.3 lib/awspec/ext/string.rb
awspec-0.2.2 lib/awspec/ext/string.rb
awspec-0.2.1 lib/awspec/ext/string.rb
awspec-0.2.0 lib/awspec/ext/string.rb
awspec-0.1.1 lib/awspec/ext/string.rb