Sha256: 8b76584643ed249a6bde2d669798e7ee513091b79d6f13440add43a6ac3f67ee

Contents?: true

Size: 547 Bytes

Versions: 29

Compression:

Stored size: 547 Bytes

Contents

class String
  # Replaces spaces and tabs with _ so we can use the string as a method name
  # Also replace dangerous punctuation
  def to_method_name
    self.downcase.gsub(/[\s:',\.~;!#=\(\)&]+/,'_')
  end
  
  # Borrowed from +camelize+ in ActiveSupport
  def to_module_name
    self.to_method_name.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end
  
  # Borrowed from +camelize+ in ActiveSupport
  def to_class_name
    self.to_method_name.gsub(/\/(.?)/) { "#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  end
end

Version data entries

29 entries across 29 versions & 4 rubygems

Version Path
auser-poolparty-1.3.0 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.1 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.10 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.11 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.12 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.13 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.14 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.15 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.16 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.17 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.2 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.3 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.4 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.5 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.6 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.7 vendor/gems/context/lib/context/core_ext/string.rb
auser-poolparty-1.3.8 vendor/gems/context/lib/context/core_ext/string.rb
djsun-context-0.5.5 lib/context/core_ext/string.rb
fairchild-poolparty-1.3.17 vendor/gems/context/lib/context/core_ext/string.rb
fairchild-poolparty-1.3.5 vendor/gems/context/lib/context/core_ext/string.rb