File tree 3 files changed +17
-10
lines changed
3 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ AllCops:
13
13
Layout/LineLength :
14
14
Max : 80
15
15
16
+ Lint/AmbiguousBlockAssociation :
17
+ Enabled : false
18
+
16
19
Lint/DuplicateBranch :
17
20
Enabled : false
18
21
Original file line number Diff line number Diff line change 22
22
23
23
require_relative "syntax_tree/parser"
24
24
25
- # We rely on Symbol#name being available, which is only available in Ruby 3.0+.
26
- # In case we're running on an older Ruby version, we polyfill it here.
27
- unless :+ . respond_to? ( :name )
28
- class Symbol # rubocop:disable Style/Documentation
29
- def name
30
- to_s . freeze
31
- end
32
- end
33
- end
34
-
35
25
# Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
36
26
# provides the ability to generate a syntax tree from source, as well as the
37
27
# tools necessary to inspect and manipulate that syntax tree. It can be used to
Original file line number Diff line number Diff line change @@ -1651,6 +1651,20 @@ def format(q)
1651
1651
# array << value
1652
1652
#
1653
1653
class Binary < Node
1654
+ # Since Binary's operator is a symbol, it's better to use the `name` method
1655
+ # than to allocate a new string every time. This is a tiny performance
1656
+ # optimization, but enough that it shows up in the profiler. Adding this in
1657
+ # for older Ruby versions.
1658
+ unless :+ . respond_to? ( :name )
1659
+ using Module . new {
1660
+ refine Symbol do
1661
+ def name
1662
+ to_s . freeze
1663
+ end
1664
+ end
1665
+ }
1666
+ end
1667
+
1654
1668
# [untyped] the left-hand side of the expression
1655
1669
attr_reader :left
1656
1670
You can’t perform that action at this time.
0 commit comments