Module: Rensei::Unparser::Ruby3_0_0
Instance Method Summary collapse
-
#NODE_CASE3(node, opt = {}) ⇒ Object
case statement (pattern matching) format: case [nd_head]; [nd_body]; end example: case x; in 1; foo; in 2; bar; else baz; end.
-
#NODE_DEFN(node, opt = {}) ⇒ Object
method definition format: def [nd_mid] [nd_defn]; end example: def foo; bar; end.
-
#NODE_DEFS(node, opt = {}) ⇒ Object
singleton method definition format: def [nd_recv]. [nd_defn]; end example: def obj.foo; bar; end.
-
#NODE_DSTR(node, opt = {}) ⇒ Object
string literal with interpolation format: [nd_lit] example: "foo#{ bar }baz".
-
#NODE_FNDPTN(node, opt = {}) ⇒ Object
find pattern format: [nd_pconst](*, args, …, *[post_rest_arg]).
-
#NODE_ITER(node, opt = {}) ⇒ Object
method call with block format: [nd_iter] { [nd_body] } example: 3.times { foo }.
Methods included from Base
Instance Method Details
#NODE_CASE3(node, opt = {}) ⇒ Object
case statement (pattern matching) format: case [nd_head]; [nd_body]; end example: case x; in 1; foo; in 2; bar; else baz; end
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 |
# 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 = {}) ⇒ Object
method definition format: def [nd_mid] [nd_defn]; end example: def foo; bar; end
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 |
# 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 = {}) ⇒ Object
singleton method definition format: def [nd_recv]. [nd_defn]; end example: def obj.foo; bar; end
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 |
# 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 = {}) ⇒ Object
string literal with interpolation format: [nd_lit] example: "foo#{ bar }baz"
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 |
# 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 = {}) ⇒ Object
find pattern format: [nd_pconst](*, args, …, *[post_rest_arg])
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 |
# 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 = {}) ⇒ Object
method call with block format: [nd_iter] { [nd_body] } example: 3.times { foo }
1529 1530 1531 |
# File 'lib/rensei/unparser.rb', line 1529 def NODE_ITER(node, opt = {}) super(node, opt.merge(ignore_numbered_paramters: true)) end |