From 11eab86cc0ba1aecaa0dbb5e4a530cec274aa989 Mon Sep 17 00:00:00 2001 From: Mariano Simone Date: Mon, 5 Feb 2024 22:12:36 -0800 Subject: [PATCH] [Ruby] Delegate difference, intersection, union from RepeatedField to Array (#15652) Coming from [[protobuf/issues/15180] [Ruby] Support for currently ignored Array methods in `RepeatedField`](https://github.com/protocolbuffers/protobuf/issues/15180) This adds a couple of `Array` methods to what gets delegated from `RepeatedField`. - `intersection`, because `|` was already delegated - `union`, because `&` was already delegated - `difference`, because `-` was already delegated Closes #15652 COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15652 from marianosimone:delegate_rb_array_methods 2971981338fdca57a63ec675b597b197c6ef4015 PiperOrigin-RevId: 604534655 --- ruby/lib/google/protobuf/repeated_field.rb | 6 +++--- ruby/tests/repeated_field_test.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ruby/lib/google/protobuf/repeated_field.rb b/ruby/lib/google/protobuf/repeated_field.rb index b8c71e0655010..53de122f3470b 100644 --- a/ruby/lib/google/protobuf/repeated_field.rb +++ b/ruby/lib/google/protobuf/repeated_field.rb @@ -47,12 +47,12 @@ class RepeatedField def_delegators :to_ary, :&, :*, :-, :'<=>', :assoc, :bsearch, :bsearch_index, :combination, :compact, :count, - :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten, - :include?, :index, :inspect, :join, + :cycle, :difference, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten, + :include?, :index, :inspect, :intersection, :join, :pack, :permutation, :product, :pretty_print, :pretty_print_cycle, :rassoc, :repeated_combination, :repeated_permutation, :reverse, :rindex, :rotate, :sample, :shuffle, :shelljoin, - :to_s, :transpose, :uniq, :| + :to_s, :transpose, :union, :uniq, :| def first(n=nil) diff --git a/ruby/tests/repeated_field_test.rb b/ruby/tests/repeated_field_test.rb index 492d9d928fe00..41f90b49325bc 100755 --- a/ruby/tests/repeated_field_test.rb +++ b/ruby/tests/repeated_field_test.rb @@ -22,9 +22,9 @@ def test_acts_like_an_array arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index, :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple, :nitems, :iter_for_reverse_each, :indexes, :append, :prepend] - arr_methods -= [:union, :difference, :filter!] + arr_methods -= [:filter!] # ruby 2.7 methods we can ignore - arr_methods -= [:intersection, :deconstruct, :resolve_feature_path] + arr_methods -= [:deconstruct, :resolve_feature_path] # ruby 3.1 methods we can ignore arr_methods -= [:intersect?] arr_methods.each do |method_name|