Module: Ethon::Extensions::String

Defined in:
lib/ethon/extensions/string.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#byteslice(*args) ⇒ String

Return part of the string.

Returns:

  • (String)

    Part of the string.



12
13
14
# File 'lib/ethon/extensions/string.rb', line 12

def byteslice(*args)
  self[*args]
end

#underscrString

Convert string to underscore. Taken from activesupport, renamed in order to no collide with it.

Examples:

Underscore.

"ClassName".underscr
#=> "class_name"

Returns:

  • (String)

    Underscore string.



26
27
28
29
30
31
32
33
34
35
# File 'lib/ethon/extensions/string.rb', line 26

def underscr
  word = self.dup
  word.gsub!('::', '_')
  word.gsub!(/(?:([A-Za-z\d])|^)(#{/(?=a)b/})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end