Project

General

Profile

Actions

Bug #13169

closed

Fix OpenStruct#each_pair return value

Added by stomar (Marcus Stollsteimer) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]
[ruby-core:79309]

Description

ostruct.rb: fix OpenStruct#each_pair return value

* lib/ostruct.rb (OpenStruct#each_pair): let #each_pair
  with block return self instead of the internal hash table.

Currently OpenStruct#each_pair with block returns the internal hash table, while usually #each, #each_key, #each_byte, and similar methods return self. Struct#each_pair also returns self.

require "ostruct"
person = OpenStruct.new(name: "John", age: 70)

person                # => #<OpenStruct name="John", age=70>
person.each_pair { }  # => {:name=>"John", :age=>70}

I don't know whether this is intended behavior or only an oversight.

The patch makes OpenStruct#each_pair return self, and also adds a test. (I do not know anything about how tests/specs in the Ruby source are organized, I hope it's fine.)


Files

ostruct_each_pair.patch (908 Bytes) ostruct_each_pair.patch stomar (Marcus Stollsteimer), 01/30/2017 08:51 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0