Class: String

Inherits:
Object show all
Defined in:
lib/ergane/core_ext/object.rb,
lib/ergane/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#blank?Boolean

Catch whitespace-only strings, overriding the inherited Object#blank?. Guarded on String’s OWN methods — not method_defined?, which would see the inherited Object#blank? and skip, leaving the whitespace-blind version. This still defines our version normally, but yields to any external String#blank? (e.g. ActiveSupport) rather than clobbering it.

Returns:

  • (Boolean)


40
41
42
# File 'lib/ergane/core_ext/object.rb', line 40

def blank?
  empty? || /\A[[:space:]]*\z/.match?(self)
end

#demodulizeObject

“Ergane::Deploy” -> “Deploy”



15
16
17
18
19
20
21
# File 'lib/ergane/core_ext/string.rb', line 15

def demodulize
  if (index = rindex("::"))
    self[(index + 2)..]
  else
    dup
  end
end

#underscoreObject

“DeployCommand” -> “deploy_command” “Ergane::Deploy” -> “ergane/deploy”



6
7
8
9
10
11
12
# File 'lib/ergane/core_ext/string.rb', line 6

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