Module: Async::Enumerable::Comparable

Defined in:
lib/async/enumerable/comparable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/async/enumerable/comparable.rb', line 4

def self.included(base)
  base.include(::Comparable)
end

Instance Method Details

#<=>(other) ⇒ Integer?

Compares with another enumerable.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Integer, nil)

    Comparison result



11
12
13
14
# File 'lib/async/enumerable/comparable.rb', line 11

def <=>(other)
  return nil unless other.respond_to?(:to_a)
  to_a <=> other.to_a
end

#==(other) ⇒ Boolean Also known as: eql?

Checks equality with another enumerable.

Parameters:

  • other (Object)

    Object to compare

Returns:

  • (Boolean)

    True if equal



19
20
21
22
# File 'lib/async/enumerable/comparable.rb', line 19

def ==(other)
  return false unless other.respond_to?(:to_a)
  to_a == other.to_a
end