Bug #5305

YAML::DBM#update、#replace のコメントの間違いを修正する

Added by Sho Hashimoto over 3 years ago. Updated over 2 years ago.

[ruby-dev:44485]
Status:Closed
Priority:Low
Assignee:Ayumu AIZAWA
ruby -v:ruby 1.9.4dev (2011-09-19 trunk 33297) [x86_64-linux] Backport:

Description

YAML::DBM#update、#replace のコメントに each メソッドや each_pair
メソッドがあれば引数として指定できる旨の記述がありますが、実際には
keys.each しているため、正しくないようです。

Associated revisions

Revision 33329
Added by Ayumu AIZAWA over 3 years ago

  • lib/yaml/dbm/dbm.rb: fix #update, add #key for using istead #index. [Bug #5305]

Revision 33329
Added by Ayumu AIZAWA over 3 years ago

  • lib/yaml/dbm/dbm.rb: fix #update, add #key for using istead #index. [Bug #5305]

History

#1 Updated by Ayumu AIZAWA over 3 years ago

  • ruby -v changed from ruby 1.9.4dev (2011-09-10 trunk 33240) [x86_64-linux] to -

Hi Guys,

The comments of YAML::DBM#update and #replace says it requires only
'each and each_pair', but they are using 'keys.each' actually.

I think the comment should be modified, so I hope someone provide a draft.

Following is the original comment of YAML#update and #replace:
#update:
"Updates the database with multiple values from the specified object.
Takes any object which implements the each_pair method, including Hash
and DBM objects. Returns +self+."

#replace:
"Replaces the contents of the database with the contents of the
specified object.
Takes any object which implements the each_pair method, including Hash and
DBM objects."

Regards

Ayumu AIZAWA

#2 Updated by Ayumu AIZAWA over 3 years ago

  • Assignee set to Ayumu AIZAWA
  • Target version set to 2.0.0
  • ruby -v changed from - to ruby 1.9.4dev (2011-09-19 trunk 33297) [x86_64-linux]

I think, YAML::DBM#update be able to rewrite without #keys.

--- lib/yaml/dbm.rb
+++ lib/yaml/dbm.rb
@@ -185,8 +185,8 @@ class DBM < ::DBM
#
# Returns +self+.
def update( hsh )
- hsh.keys.each do |k|
- self.store( k, hsh.fetch( k ) )
+ hsh.each_pair do |k,v|
+ self.store( k, v )
end
self

end

But there are no test for YAML::DBM, so I'm writing test for these now.
After my work, this issue would be closed.

#3 Updated by Ayumu AIZAWA over 3 years ago

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

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


  • lib/yaml/dbm/dbm.rb: fix #update, add #key for using istead #index. [Bug #5305]

Also available in: Atom PDF