Skip to content

Commit

Permalink
Enabled uniq method by changing Ocran::Pathname comparison method
Browse files Browse the repository at this point in the history
Changed the basis of the comparison method from `==` to `eql?`, enabling the `uniq` method on arrays of `Pathname` objects.

- Defined the `eql?` method to check the equality of `Pathname` objects.
- Redefined `==` and `===` methods as aliases of `eql?`.
- Added comments to the `eql?` method to explain that this method enables the `uniq` method on arrays of `Pathname` objects.
  • Loading branch information
shinokaro committed May 28, 2024
1 parent a7d7c34 commit 2d70aa7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ module Ocran
end
end

# Checks if two Ocran::Pathname objects are equal, considering the file system's
# Checks if two Pathname objects are equal, considering the file system's
# case sensitivity and path separators. Returns false if the other object is not
# an Ocran::Pathname.
def ==(other)
return false unless other.is_a?(Ocran::Pathname)
# an Pathname.
# This method enables the use of the `uniq` method on arrays of Pathname objects.
def eql?(other)
return false unless other.is_a?(Pathname)

a = to_posix
b = other.to_posix
pathequal(a, b)
end

alias === ==
alias eql? ==
alias == eql?
alias === eql?

# The drive_letter? method retrieves the drive letter from the current path
# in a Windows environment. This method returns the drive letter as a string
Expand Down

0 comments on commit 2d70aa7

Please sign in to comment.