Class: Cassandra::Types::Tuple

Inherits:
Cassandra::Type show all
Defined in:
lib/cassandra/types.rb

Instance Method Summary collapse

Instance Method Details

#assert(value, message = nil, &block) ⇒ void

This method returns an undefined value.

Asserts that a given value is an Cassandra::Tuple

Parameters:

  • value (Object)

    value to be validated

  • message (String) (defaults to: nil)

    error message to use when assertion fails

Yield Returns:

  • (String)

    error message to use when assertion fails

Raises:

  • (ArgumentError)

    if the value is not an Cassandra::Tuple

See Also:



972
973
974
975
976
977
978
979
# File 'lib/cassandra/types.rb', line 972

def assert(value, message = nil, &block)
  Util.assert_instance_of(Cassandra::Tuple, value, message, &block)
  Util.assert(value.size <= @members.size, message, &block)
  @members.each_with_index do |type, i|
    Util.assert_type(type, value[i], message, &block)
  end
  nil
end

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

Returns:



987
988
989
# File 'lib/cassandra/types.rb', line 987

def eql?(other)
  other.is_a?(Tuple) && @members == other.members
end

#kindSymbol

Returns :tuple.

Returns:

  • (Symbol)

    :tuple

See Also:



945
946
947
# File 'lib/cassandra/types.rb', line 945

def kind
  :tuple
end

#new(*values) ⇒ Cassandra::Tuple

Coerces the value to Cassandra::Tuple

Examples:

Creating a tuple

include Cassandra::Types

tuple(varchar, varchar, int).new('Jane', 'Smith', 38) # => (Jane, Smith, 38)

Parameters:

  • values (*Object)

    tuple values

Returns:

See Also:



957
958
959
960
961
962
963
# File 'lib/cassandra/types.rb', line 957

def new(*values)
  Util.assert(values.size <= @members.size) { "too many values: #{values.size} out of max #{@members.size}" }
  values.each_with_index do |v, i|
    Util.assert_type(@members[i], v)
  end
  Cassandra::Tuple::Strict.new(@members, values)
end

#to_sString

Returns "tuple<type, type, type...>".

Returns:

  • (String)

    "tuple<type, type, type...>"

See Also:



983
984
985
# File 'lib/cassandra/types.rb', line 983

def to_s
  "tuple<#{@members.map(&:to_s).join(', ')}>"
end