Class: Handlebars::Helpers::CodeRuby::Demodulize

Inherits:
BaseHelper
  • Object
show all
Defined in:
lib/handlebars/helpers/code_ruby/demodulize.rb

Overview

Demodulize: Removes the module part from the expression in the string.

Instance Method Summary collapse

Methods inherited from BaseHelper

#parse_json, #struct_to_hash, #tokenizer, #wrapper

Instance Method Details

#handlebars_helperObject



52
53
54
# File 'lib/handlebars/helpers/code_ruby/demodulize.rb', line 52

def handlebars_helper
  proc { |_context, value| wrapper(parse(value)) }
end

#parse(value) ⇒ String

Parse will demodulize, aka remove the module part from the expression in the string.

Examples:


puts Demodulize.new.parse('ActiveSupport::Inflector::Inflections')

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

puts Demodulize.new.parse('Inflections')

Inflections

puts Demodulize.new.parse('::Inflections')

Inflections

puts Demodulize.new.parse('')

""

Parameters:

  • value (String)
    • name of the ruby module and class name separated by

Returns:

  • (String)

    value demodulize, aka class name without module



46
47
48
49
50
# File 'lib/handlebars/helpers/code_ruby/demodulize.rb', line 46

def parse(value)
  return '' if value.nil?

  value.demodulize
end