Skip to main content Module ast_helpers Copy item path Source arg_count Count arguments from a CallNode’s arguments (excluding block argument which is in block field). block_arg_names Get block argument names from a BlockNode’s parameters.
BlockNode.parameters() returns Option which is typically a BlockParametersNode. body_expression_count Count the number of top-level expressions in a body node. body_single_expression Get the single expression from a body node, if the body has exactly one expression.
For StatementsNode bodies, returns the first (and only) statement.
For single-expression bodies (non-StatementsNode), returns the body node itself.
Returns None if body is empty or has multiple expressions. byte_offset_to_line Convert a byte offset to a 1-based line number using pre-computed newline positions. call_args_pair Get the first two arguments from a CallNode as a tuple (without collecting all). compute_newline_positions Compute byte positions of all newline characters in source. def_block_arg_name Check if a DefNode has a block argument (&block), returning its name if so. def_first_arg_name Get the first regular argument name from a DefNode. def_regular_arg_count Count regular (required) arguments in a DefNode. first_arg_is_single_pair_hash Check if the first argument is a Hash/KeywordHash node with exactly one key-value pair.
h.merge!(item: 1) parses as KeywordHashNode, h.merge!({item: 1}) parses as HashNode.
Check if the first argument of a CallNode is a Hash/KeywordHash with exactly one pair. first_call_arg Get the first argument from a CallNode (without allocating a Vec). has_block_pass Check if a CallNode has a BlockArgumentNode in its block field. has_full_block Check if a CallNode has a full BlockNode (not just a BlockArgumentNode). is_int_one Check if a node is an IntegerNode with value 1. is_primitive Check if a node is a literal/primitive (not a variable reference or method call). is_single_char_string Check if a node is a single-character string literal. receiver_as_call Extract the inner CallNode from a receiver, if it is one. receiver_is_call_with_name Check if a node is a CallNode with the given method name. receiver_is_range Check if the receiver is a range (RangeNode, inclusive or exclusive).
Also handles parenthesized ranges: (1..10) parses as ParenthesesNode(RangeNode). str_contains_def Check if a string literal contains “def”.