123456789_123456789_123456789_123456789_123456789_

Module: YARD::Parser::Ruby

Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Extended In:
Included In:
Defined in: lib/yard/autoload.rb,
lib/yard/parser/ruby/ast_node.rb,
lib/yard/parser/ruby/ruby_parser.rb,
lib/yard/parser/ruby/token_resolver.rb,
lib/yard/parser/ruby/legacy/ruby_parser.rb

Overview

Ruby parsing components.

Instance Method Summary

Instance Method Details

#s(*nodes, opts = {}) ⇒ AstNode #s(type, *children, opts = {}) ⇒ AstNode

Builds and s-expression by creating Ruby::AstNode objects with the type provided by the first argument.

Examples:

An implicit list of keywords

ast = s(s(:kw, "if"), s(:kw, "else"))
ast.type # => :list

A method call

s(:command, s(:var_ref, "mymethod"))

Overloads:

  • #s(*nodes, opts = {}) ⇒ AstNode

    Parameters:

    • nodes (Array<AstNode>)

      a list of nodes.

    • opts (Hash) (defaults to: {})

      any extra options (docstring, file, source) to set on the object

    Returns:

    • (AstNode)

      an implicit node where node.type == :list

  • #s(type, *children, opts = {}) ⇒ AstNode

    Parameters:

    • type (Symbol)

      the node type

    • children (Array<AstNode>)

      any child nodes inside this one

    • opts (Hash) (defaults to: {})

      any extra options to set on the object

    Returns:

    • (AstNode)

      a node of type type.

See Also:

  • AstNode#initialize
[ GitHub ]

  
# File 'lib/yard/parser/ruby/ast_node.rb', line 25

def s(*args)
  type = Symbol === args.first ? args.shift : :list
  opts = Hash === args.last ? args.pop : {}
  AstNode.node_class_for(type).new(type, args, opts)
end