Class: Cassandra::Tuple

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/cassandra/tuple.rb

Instance Method Summary collapse

Constructor Details

#initialize(*values) ⇒ Tuple

Constructs a tuple with given values



65
66
67
# File 'lib/cassandra/tuple.rb', line 65

def initialize(*values)
  @values = values
end

Instance Method Details

#[](i) ⇒ Object

Returns value of the tuple at position i.

Parameters:

  • i (Integer)

    numeric index of the value inside the tuple, must be 0 < i < tuple.size

Returns:

  • (Object)

    value of the tuple at position i



79
80
81
# File 'lib/cassandra/tuple.rb', line 79

def [](i)
  @values[Integer(i)]
end

#[]=(i, value) ⇒ Object

Returns value of the tuple at position i.

Parameters:

  • i (Integer)

    numeric index of the value inside the tuple, must be 0 < i < tuple.size

  • value (Object)

    a value to assign at position i

Returns:

  • (Object)

    value of the tuple at position i

Raises:

  • (IndexError)

    when index is outside of tuple bounds



98
99
100
101
102
# File 'lib/cassandra/tuple.rb', line 98

def []=(i, value)
  i = Integer(i)
  raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}" if i < 0 || i >= @values.size
  @values[i] = value
end

#each {|value| ... } ⇒ Object

Iterates over all values of the tuple

Yield Parameters:

  • value (Object)

    current value



71
72
73
74
# File 'lib/cassandra/tuple.rb', line 71

def each(&block)
  @values.each(&block)
  self
end

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

Returns:

  • (Boolean)


119
120
121
# File 'lib/cassandra/tuple.rb', line 119

def eql?(other)
  other == @values
end

#fetch(i) ⇒ Object

Returns value of the tuple at position i.

Parameters:

  • i (Integer)

    numeric index of the value inside the tuple, must be 0 < i < tuple.size

Returns:

  • (Object)

    value of the tuple at position i

Raises:

  • (IndexError)

    when index is outside of tuple bounds



87
88
89
90
91
# File 'lib/cassandra/tuple.rb', line 87

def fetch(i)
  i = Integer(i)
  raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}" if i < 0 || i >= @values.size
  @values[i]
end

#inspectObject



115
116
117
# File 'lib/cassandra/tuple.rb', line 115

def inspect
  "#<Cassandra::Tuple:0x#{self.object_id.to_s(16)} #{to_s}>"
end

#sizeInteger

Returns tuple size

Returns:

  • (Integer)

    tuple size



106
107
108
# File 'lib/cassandra/tuple.rb', line 106

def size
  @values.size
end

#to_sObject

String representation of the tuple



111
112
113
# File 'lib/cassandra/tuple.rb', line 111

def to_s
  "(#{@values.map(&:to_s).join(', ')})"
end