module Rensei::Unparser::Ruby3_0_0
Public Instance Methods
NODE_CASE3(node, opt = {})
click to toggle source
case statement (pattern matching) format: case [nd_head]; [nd_body]; end example: case x; in 1; foo; in 2; bar; else baz; end
Calls superclass method
# File lib/rensei/unparser.rb, line 1550 def NODE_CASE3(node, opt = {}) node.children.then { |head, body, else_| # Add super `42 => result` if body.children[1].nil? "#{unparse(head, opt)} => #{unparse(body, opt.merge(without_in: true))}" else super end } end
NODE_DEFN(node, opt = {})
click to toggle source
method definition format: def [nd_mid] [nd_defn]; end example: def foo; bar; end
Calls superclass method
# File lib/rensei/unparser.rb, line 1591 def NODE_DEFN(node, opt = {}) node.children.then { |mid, defn| # Add support `def hoge = 42` if defn.children[1].nil? info = unparse_NODE_SCOPE(defn, opt) "def #{mid} = #{info[:body]}" else super end } end
NODE_DEFS(node, opt = {})
click to toggle source
singleton method definition format: def [nd_recv]. [nd_defn]; end example: def obj.foo; bar; end
Calls superclass method
# File lib/rensei/unparser.rb, line 1606 def NODE_DEFS(node, opt = {}) node.children.then { |recv, mid, defn| # Add support `def obj.hoge = 42` if defn.children[1].nil? info = unparse_NODE_SCOPE(defn, opt) "def #{unparse(recv, opt)}.#{mid} = #{info[:body]}" else super end } end
NODE_DSTR(node, opt = {})
click to toggle source
string literal with interpolation format: [nd_lit] example: "foo#{ bar }baz"
Calls superclass method
# File lib/rensei/unparser.rb, line 1536 def NODE_DSTR(node, opt = {}) node.children.then { |prefix, lit, suffix| # Add support `"foo#{ "hoge" }baz"` if lit.nil? && suffix.nil? "\"\#{#{prefix.dump}\}\"" else super end } end
NODE_FNDPTN(node, opt = {})
click to toggle source
find pattern format: [nd_pconst](*, args, …, *[post_rest_arg])
# File lib/rensei/unparser.rb, line 1563 def NODE_FNDPTN(node, opt = {}) node.children.then { |pconst, pre, rest, post| # e.g. in Array[a, b] pconst_ = unparse(pconst, opt) if pconst opt_flags = { expand_ARRAY: true, expand_HASH: true, pattern_match_OR: true, pattern_match_LVAR: true } if pre == :NODE_SPECIAL_NO_NAME_REST pre_ = "*" elsif pre pre_ = "*#{unparse(pre, opt.merge(opt_flags))}" end rest_ = unparse(rest, opt.merge(opt_flags)) if post == :NODE_SPECIAL_NO_NAME_REST post_ = "*" elsif post post_ = "*#{unparse(post, opt.merge(opt_flags))}" end "#{pconst_}[#{[pre_, rest_, post_].compact.join(", ")}]" } end
NODE_ITER(node, opt = {})
click to toggle source
method call with block format: [nd_iter] { [nd_body] } example: 3.times { foo }
Calls superclass method
# File lib/rensei/unparser.rb, line 1529 def NODE_ITER(node, opt = {}) super(node, opt.merge(ignore_numbered_paramters: true)) end