Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Ruby 2.4, Set#=== is harmonized with Ruby 2.5+ to call include? #94

Merged
merged 1 commit into from Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

* [#94](https://github.com/rubocop-hq/rubocop-ast/pull/94): In Ruby 2.4, `Set#===` is harmonized with Ruby 2.5+ to call `include?`. ([@marcandre][])

## 0.3.0 (2020-08-01)

### New features
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/ast.rb
Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions lib/rubocop/ast/ext/set.rb
@@ -0,0 +1,12 @@
# frozen_string_literal: true

test = :foo
case test
when Set[:foo]
# ok, RUBY_VERSION > 2.4
else
# Harmonize `Set#===`
class Set
alias === include?
end
end
9 changes: 9 additions & 0 deletions spec/rubocop/ast/ext/set_spec.rb
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# rubocop:disable RSpec/DescribeClass, Style/CaseEquality
RSpec.describe 'Set#===' do
it 'tests for inclusion' do
expect(Set[1, 2, 3] === 2).to eq true
end
end
# rubocop:enable RSpec/DescribeClass, Style/CaseEquality