From ce9e14e578af9b39de8edd6e7a2a48e40201420c Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Mon, 10 Aug 2020 23:20:19 -0400 Subject: [PATCH] In Ruby 2.4, `Set#===` is harmonized with Ruby 2.5+ to call `include?` --- CHANGELOG.md | 4 ++++ lib/rubocop/ast.rb | 1 + lib/rubocop/ast/ext/set.rb | 8 ++++++++ 3 files changed, 13 insertions(+) create mode 100644 lib/rubocop/ast/ext/set.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index ede2be76e..75675fb71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ * [#89](https://github.com/rubocop-hq/rubocop-ast/pull/89): Support right hand assignment for Ruby 2.8 (3.0) parser. ([@koic][]) * [#93](https://github.com/rubocop-hq/rubocop-ast/pull/93): Add `Node#{left|right}_sibling{s}` ([@marcandre][]) +### Changes + +* [#x](https://github.com/rubocop-hq/rubocop-ast/issue/x): In Ruby 2.4, `Set#===` is harmonized with Ruby 2.5+ to call `include?`. ([@marcandre][]) + ## 0.3.0 (2020-08-01) ### New features diff --git a/lib/rubocop/ast.rb b/lib/rubocop/ast.rb index 253e80a3f..153ada376 100644 --- a/lib/rubocop/ast.rb +++ b/lib/rubocop/ast.rb @@ -5,6 +5,7 @@ require 'set' require_relative 'ast/ext/range' +require_relative 'ast/ext/set' require_relative 'ast/node_pattern' require_relative 'ast/sexp' require_relative 'ast/node' diff --git a/lib/rubocop/ast/ext/set.rb b/lib/rubocop/ast/ext/set.rb new file mode 100644 index 000000000..89061b055 --- /dev/null +++ b/lib/rubocop/ast/ext/set.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +# Harmonize `Set#===` +unless Set[:foo] === :foo # typically RUBY_VERSION <= 2.4 + class Set + alias === include? + end +end