Method: YARD::CodeObjects::MacroObject.apply

Defined in:
lib/yard/code_objects/macro_object.rb

.apply(docstring, call_params = [], full_source = '', block_source = '', _method_object = nil) ⇒ String

Applies a macro on a docstring by creating any macro data inside of the docstring first. Equivalent to calling find_or_create and apply_macro on the new macro object.

Parameters:

  • docstring (Docstring)

    the docstring to create a macro out of

  • call_params (Array<String>) (defaults to: [])

    the method name and parameters to the method call. These arguments will fill $0-N

  • full_source (String) (defaults to: '')

    the full source line (excluding block) interpolated as $*

  • block_source (String) (defaults to: '')

    Currently unused. Will support interpolating the block data as a variable.

Returns:

  • (String)

    the expanded macro data

See Also:



119
120
121
122
123
124
125
126
127
# File 'lib/yard/code_objects/macro_object.rb', line 119

def apply(docstring, call_params = [], full_source = '', block_source = '', _method_object = nil) # rubocop:disable Lint/UnusedMethodArgument
  docstring = docstring.all if Docstring === docstring
  parser = Docstring.parser
  handler = OpenStruct.new
  handler.call_params = call_params[1..-1]
  handler.caller_method = call_params.first
  handler.statement = OpenStruct.new(:source => full_source)
  parser.parse(docstring, nil, handler).to_docstring.to_raw
end