Problem determining uniqueness in array of arrays

I create an array of arrays, each inner array containing the mtime value
and fully qualified pathname of a file.

sources = [ [ mtime.to_i, “filename” ], [. . . ] ]

It happens that the same file is occasionally added twice or more. I
want to eliminate the duplicates. I thought that sources.uniq! would
work but I was surprised to discover that it returned nil indicating
that there were no duplicates found. I then tried sources.uniq.sort to
see if this was true and saw this:

  1276181402
  acrfile.0610104802

  1276181402
  acrfile.0610104802

  1276181402
  acrfile.0610104802

All elements of the outer array belong to class Array. The class of the
first element in each inner array is Fixnum, that of the second is
String.

So, what is it about Array#uniq that I misapprehend? Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?

James B. wrote in post #979634:

So, what is it about Array#uniq that I misapprehend? Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?

I discovered my error. The Pathname varied ever so slightly

On Sat, Feb 5, 2011 at 12:31 AM, James B. [email protected]
wrote:

So, what is it about Array#uniq that I misapprehend? Why do three
apparently identical inner arrays remain in the outer array after #uniq
is applied to it?

pls show your code.

eg,

sources=[ [1276181402, “acrfile.0610104802”],
[1276181402, “acrfile.0610104802”],
[1276181402, “acrfile.0610104802”],
]
#=> [[1276181402, “acrfile.0610104802”], [1276181402,
“acrfile.0610104802”], [1276181402, “acrfile.0610104802”]]

p sources.uniq
[[1276181402, “acrfile.0610104802”]]
#=> [[1276181402, “acrfile.0610104802”]]

p sources.uniq.sort
[[1276181402, “acrfile.0610104802”]]
#=> [[1276181402, “acrfile.0610104802”]]

p sources.uniq!
[[1276181402, “acrfile.0610104802”]]
#=> [[1276181402, “acrfile.0610104802”]]

sources
#=> [[1276181402, “acrfile.0610104802”]]

best regards -botp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs