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)


31
32
33
# File 'lib/convenient_service/utils/string/demodulize.rb', line 31

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

Instance Method Details

#callString

Returns:



47
48
49
50
51
# File 'lib/convenient_service/utils/string/demodulize.rb', line 47

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

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