Class/Module Index [+]

Quicksearch

YARD::Templates::Helpers::MethodHelper

Helper methods for method objects.

Public Instance Methods

format_args(object) click to toggle source

@return [String] formatted arguments for a method

# File lib/yard/templates/helpers/method_helper.rb, line 6
def format_args(object)
  return if object.parameters.nil?
  params = object.parameters
  if object.has_tag?(:yield) || object.has_tag?(:yieldparam)
    params.reject! do |param|
      param[0].to_s[0,1] == "&" &&
        !object.tags(:param).any? {|t| t.name == param[0][1..-1] }
    end
  end

  unless params.empty?
    args = params.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ")
    h("(#{args})")
  else
    ""
  end
end
format_block(object) click to toggle source

@return [String] formatted block if one exists

# File lib/yard/templates/helpers/method_helper.rb, line 32
def format_block(object)
  if object.has_tag?(:yield) && object.tag(:yield).types
    params = object.tag(:yield).types
  elsif object.has_tag?(:yieldparam)
    params = object.tags(:yieldparam).map {|t| t.name }
  elsif object.has_tag?(:yield)
    return "{ ... }"
  else
    params = nil
  end

  params ? h("{|" + params.join(", ") + "| ... }") : ""
end
format_code(object, show_lines = false) click to toggle source

@return [String] formats source of an object

# File lib/yard/templates/helpers/method_helper.rb, line 54
def format_code(object, show_lines = false)
  i = -1
  lines = object.source.split(/\n/)
  longestline = (object.line + lines.size).to_s.length
  lines.map do |line|
    lineno = object.line + (i += 1)
    (" " * (longestline - lineno.to_s.length)) + lineno.to_s + "    " + line
  end.join("\n")
end
format_constant(value) click to toggle source

@return [String] formats source code of a constant value

# File lib/yard/templates/helpers/method_helper.rb, line 65
def format_constant(value)
  sp = value.split("\n").last[/^(\s+)/, 1]
  num = sp ? sp.size : 0
  html_syntax_highlight value.gsub(/^\s{#{num}}/, '')
end
format_lines(object) click to toggle source

@return [String] formats line numbers for source code of an object

# File lib/yard/templates/helpers/method_helper.rb, line 47
def format_lines(object)
  return "" if object.source.nil? || object.line.nil?
  i = -1
  object.source.split(/\n/).map { object.line + (i += 1) }.join("\n")
end
format_return_types(object) click to toggle source

@return [String] formatted and linked return types for a method

# File lib/yard/templates/helpers/method_helper.rb, line 25
def format_return_types(object)
  return unless object.has_tag?(:return) && object.tag(:return).types
  return if object.tag(:return).types.empty?
  format_types [object.tag(:return).types.first], false
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.