Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: eb169f6d4418
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5eb14f58538c
Choose a head ref
  • 5 commits
  • 2 files changed
  • 2 contributors

Commits on Jun 5, 2015

  1. Copy the full SHA
    b8dbdd5 View commit details
  2. Copy the full SHA
    50d9af0 View commit details
  3. Copy the full SHA
    012c230 View commit details
  4. Copy the full SHA
    1347770 View commit details
  5. Merge pull request #3424 from kachick/struct-each_pair

    Struct#each_pair should pass an array to the given block
    Yorick Peterse committed Jun 5, 2015
    Copy the full SHA
    5eb14f5 View commit details
Showing with 15 additions and 8 deletions.
  1. +1 −1 kernel/common/struct.rb
  2. +14 −7 spec/ruby/core/struct/each_pair_spec.rb
2 changes: 1 addition & 1 deletion kernel/common/struct.rb
Original file line number Diff line number Diff line change
@@ -209,7 +209,7 @@ def each

def each_pair
return to_enum(:each_pair) { size } unless block_given?
_attrs.each { |var| yield var, instance_variable_get(:"@#{var}") }
_attrs.each { |var| yield [var, instance_variable_get(:"@#{var}")] }
self
end

21 changes: 14 additions & 7 deletions spec/ruby/core/struct/each_pair_spec.rb
Original file line number Diff line number Diff line change
@@ -4,21 +4,28 @@
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)

describe "Struct#each_pair" do
before :each do
@car = StructClasses::Car.new('Ford', 'Ranger', 2001)
end

it "passes each key value pair to the given block" do
car = StructClasses::Car.new('Ford', 'Ranger', 2001)
car.each_pair do |key, value|
value.should == car[key]
@car.each_pair do |key, value|
value.should == @car[key]
end
end

context "with a block variable" do
it "passes an array to the given block" do
@car.each_pair.map { |var| var }.should == StructClasses::Car.members.zip(@car.values)
end
end

it "returns self if passed a block" do
car = StructClasses::Car.new('Ford', 'Ranger')
car.each_pair {}.should == car
@car.each_pair {}.should equal(@car)
end

it "returns an Enumerator if not passed a block" do
car = StructClasses::Car.new('Ford', 'Ranger')
car.each_pair.should be_an_instance_of(enumerator_class)
@car.each_pair.should be_an_instance_of(enumerator_class)
end

it_behaves_like :struct_accessor, :each_pair