diff --git a/.rubocop.yml b/.rubocop.yml index 3323c741..4dbeeb33 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,9 @@ AllCops: Layout/LineLength: Max: 80 +Lint/AmbiguousBlockAssociation: + Enabled: false + Lint/DuplicateBranch: Enabled: false diff --git a/lib/syntax_tree.rb b/lib/syntax_tree.rb index 52ec700b..fbd4fcef 100644 --- a/lib/syntax_tree.rb +++ b/lib/syntax_tree.rb @@ -22,16 +22,6 @@ require_relative "syntax_tree/parser" -# We rely on Symbol#name being available, which is only available in Ruby 3.0+. -# In case we're running on an older Ruby version, we polyfill it here. -unless :+.respond_to?(:name) - class Symbol # rubocop:disable Style/Documentation - def name - to_s.freeze - end - end -end - # Syntax Tree is a suite of tools built on top of the internal CRuby parser. It # provides the ability to generate a syntax tree from source, as well as the # tools necessary to inspect and manipulate that syntax tree. It can be used to diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index dcdd0275..5162655e 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -1651,6 +1651,20 @@ def format(q) # array << value # class Binary < Node + # Since Binary's operator is a symbol, it's better to use the `name` method + # than to allocate a new string every time. This is a tiny performance + # optimization, but enough that it shows up in the profiler. Adding this in + # for older Ruby versions. + unless :+.respond_to?(:name) + using Module.new { + refine Symbol do + def name + to_s.freeze + end + end + } + end + # [untyped] the left-hand side of the expression attr_reader :left