Skip to content

Commit

Permalink
the behavior of each_index was incorrect
Browse files Browse the repository at this point in the history
when run under an array, the behavior is different than the enumerable
version
  • Loading branch information
skippy committed May 18, 2015
1 parent 23c13c8 commit 70e7c28
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ruby/lib/google/protobuf/repeated_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RepeatedField
def_delegators :to_ary,
:&, :*, :-, :'<=>',
:assoc, :bsearch, :combination, :compact, :count, :cycle,
:drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
:drop, :drop_while, :each_index, :eql?, :fetch, :find_index, :flatten,
:include?, :index, :inspect, :join,
:pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
:rassoc, :repeated_combination, :repeated_permutation, :reverse,
Expand Down Expand Up @@ -104,7 +104,6 @@ def empty?
end

# array aliases into enumerable
alias_method :each_index, :each_with_index
alias_method :slice, :[]
alias_method :values_at, :select
alias_method :map, :collect
Expand Down
14 changes: 14 additions & 0 deletions ruby/tests/repeated_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ def test_delete_at
end
end

def test_each_index
m = TestMsg::Message.new
reference_arr = %w(foo bar baz)
m.repeated_string += reference_arr.clone
check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
result = []
arr.each_index {|x| result << [x, " -- "] }
result
end
check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
arr.each_index
end
end

def test_fill
m = TestMsg::Message.new
reference_arr = %w(foo bar baz)
Expand Down

0 comments on commit 70e7c28

Please sign in to comment.