Class: ConvenientService::Utils::String::Demodulize

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/string/demodulize.rb

Overview

Examples:

demodulize('ActiveSupport::Inflector::Inflections') # => "Inflections"
demodulize('Inflections')                           # => "Inflections"
demodulize('::Inflections')                         # => "Inflections"
demodulize('')                                      # => ""

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(string) ⇒ void

Parameters:

  • string (#to_s)


26
27
28
# File 'lib/convenient_service/utils/string/demodulize.rb', line 26

def initialize(string)
  @string = string.to_s
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



20
21
22
# File 'lib/convenient_service/utils/string/demodulize.rb', line 20

def string
  @string
end

Instance Method Details

#callString

Returns:



42
43
44
45
46
# File 'lib/convenient_service/utils/string/demodulize.rb', line 42

def call
  i = string.rindex("::")

  i ? string[(i + 2)..] : string
end