Project

General

Profile

Actions

Bug #7382

closed

Struct#each_pairのyieldと他のeach_pairのそれの相違

Added by tadf (tadayoshi funaba) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.0.0dev (2012-11-18 trunk 37708) [i686-linux]
Backport:
[ruby-dev:46533]

Description

Struct#each_pairが他のeach_pairと異なります。
他はENVなども含めてassocで、Structだけvaluesなので解りにくいです。

require 'ostruct'

h = {'a'=>1, 'b'=>2}
S = Struct.new('S', 'a', 'b')
s = S.new(1, 2)
o = OpenStruct.new(h)

h.each_pair{|x| p x}
s.each_pair{|x| p x}
o.each_pair{|x| p x}

Updated by matz (Yukihiro Matsumoto) over 11 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version set to 2.0.0

おっしゃることはもっともなので、直してトラブルが起きないかどうか確認したいです。
中田さん、お願いしていい?

Matz.

Updated by matz (Yukihiro Matsumoto) over 11 years ago

  • Status changed from Open to Assigned
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37721.
tadayoshi, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


struct.c: yield assoc in each_pair

  • struct.c (rb_struct_each_pair): yield associated pairs so that
    an unsplat argument can get both, for consistency with Hash,
    OpenStruct, and etc. [ruby-dev:46533] [Bug #7382]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0