Class: Tuple

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/tuples/tuple.rb

Direct Known Subclasses

Pair

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*values) ⇒ Tuple

Returns a new instance of Tuple.



5
6
7
# File 'lib/tuples/tuple.rb', line 5

def initialize(*values)
  @values = values.flatten.freeze
end

Class Method Details

.[](*values) ⇒ Object



9
10
11
# File 'lib/tuples/tuple.rb', line 9

def self.[](*values)
  new(*values)
end

Instance Method Details

#<=>(other) ⇒ Object



13
14
15
16
# File 'lib/tuples/tuple.rb', line 13

def <=>(other)
  return unless other.kind_of? self.class
  values <=> other.values
end

#invertObject



18
19
20
# File 'lib/tuples/tuple.rb', line 18

def invert
  Tuple(*values.reverse)
end