[#60404] is RB_GC_GUARD needed in rb_io_syswrite? — Eric Wong <normalperson@...>
I haven't gotten it to crash as-is, but it seems like we need to
4 messages
2014/02/01
[#60682] volatile usages — Eric Wong <normalperson@...>
Hi all, I went ahead and removed some use of volatile which were once
5 messages
2014/02/13
[#60794] [RFC] rearrange+pack vtm and time_object structs — Eric Wong <normalperson@...>
Extracted from addendum on top of Feature #9362 (cache-aligned objects).
4 messages
2014/02/16
[#61139] [ruby-trunk - Feature #9577] [Open] [PATCH] benchmark/driver.rb: align columns in text output — normalperson@...
Issue #9577 has been reported by Eric Wong.
3 messages
2014/02/28
[ruby-core:60929] [ruby-trunk - Bug #9340] Document order related behavior in Array#uniq
From:
naruse@...
Date:
2014-02-21 07:36:26 UTC
List:
ruby-core #60929
Issue #9340 has been updated by Yui NARUSE.
Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE
----------------------------------------
Bug #9340: Document order related behavior in Array#uniq
https://bugs.ruby-lang.org/issues/9340#change-45326
* Author: Andrew Grimm
* Status: Closed
* Priority: Normal
* Assignee: Yui NARUSE
* Category:
* Target version: next minor
* ruby -v: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
* Backport: 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE
----------------------------------------
The behavior of Array#uniq without a block in Ruby 2.1.0 is inconsistent with the behavior of Array#uniq in Ruby 2.0.0, and with the behavior of Array#uniq with a block in Ruby 2.1.0.
Array#uniq without a block in Ruby 2.1.0 returns the last item that is duplicate, while everything else returns the first item that is duplicate.
class Person
attr_reader :name
def initialize(id, name)
# @id is not used by hash or eql?
@id = id
@name = name
end
def hash
[@name].hash
end
def eql?(other)
[@name].eql?([other.name])
end
end
p1 = Person.new(1, "Bob")
p2 = Person.new(2, "Bob")
p3 = Person.new(3, "Bob")
arr = [p1, p2, p3]
arr2 = arr.uniq {|p| p}
arr3 = arr.uniq
p RUBY_VERSION
p arr2
p arr3
Gives
"2.1.0"
[#<Person:0x007f1b47ef7720 @id=1, @name="Bob">]
[#<Person:0x007f1b47ef7680 @id=3, @name="Bob">]
"2.0.0"
[#<Person:0x007ffa9203bf30 @id=1, @name="Bob">]
[#<Person:0x007ffa9203bf30 @id=1, @name="Bob">]
This behavior does not contradict what RDoc says about Array#uniq, so people ought not to rely upon which duplicate item is chosen. However, at the very least, different behavior for Array#uniq with and without a block would be somewhat unexpected.
Should the documentation explicitly warn that uniq is not guaranteed to choose the first duplicate item?
As Ruby 2.1.0 has already been released, I assume it is too late to change the behavior of Array#uniq .
--
http://bugs.ruby-lang.org/