Module: YARD::Parser::Ruby

Included in:
Handlers::Ruby::Base, Handlers::Ruby::Base
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.

Defined Under Namespace

Modules: Legacy Classes: AstNode, ClassNode, CommentNode, ConditionalNode, KeywordNode, LiteralNode, LoopNode, MethodCallNode, MethodDefinitionNode, ModuleNode, ParameterNode, ReferenceNode, RipperParser, RubyParser, TokenResolver

Instance Method Summary collapse

Instance Method Details

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

Builds and s-expression by creating 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

    Returns an implicit node where node.type == :list.

    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

    Returns a node of type type.

    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:



25
26
27
28
29
# 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