Class: Handlebars::Helpers::CodeRuby::Deconstantize

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

Overview

Deconstantize: Removes the rightmost segment from the constant expression in the string.

Instance Method Summary collapse

Methods inherited from BaseHelper

#parse_json, #struct_to_hash, #tokenizer, #wrapper

Instance Method Details

#handlebars_helperObject



42
43
44
# File 'lib/handlebars/helpers/code_ruby/deconstantize.rb', line 42

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

#parse(value) ⇒ String

Parse will deconstantize, remove the rightmost segment from the constant expression in the string.

Examples:


puts Deconstantize.new.parse('Net::HTTP')

Net

puts Deconstantize.new.parse('::Net::HTTP')

::Net

puts Deconstantize.new.parse('String')

""

puts Deconstantize.new.parse('::String')

""

Parameters:

  • value (String)
    • name of the ruby constant expression

Returns:

  • (String)

    return constant without rightmost segment



36
37
38
39
40
# File 'lib/handlebars/helpers/code_ruby/deconstantize.rb', line 36

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

  value.deconstantize
end