Class: Cassandra::Types::Set

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 Set

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 Set

See Also:



914
915
916
917
918
919
920
# File 'lib/cassandra/types.rb', line 914

def assert(value, message = nil, &block)
  Util.assert_instance_of(::Set, value, message, &block)
  value.each do |v|
    Util.assert_type(@value_type, v, message, &block)
  end
  nil
end

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

Returns:



928
929
930
# File 'lib/cassandra/types.rb', line 928

def eql?(other)
  other.is_a?(Set) && @value_type == other.value_type
end

#kindSymbol

Returns :set.

Returns:

  • (Symbol)

    :set

See Also:



863
864
865
# File 'lib/cassandra/types.rb', line 863

def kind
  :set
end

#new(*value) ⇒ Set

Coerces the value to Set

Examples:

Creating a set using splat arguments

include Cassandra::Types

set(varchar).new('Jane', 'Alice', 'Loren') => #<Set: {"Jane", "Alice", "Loren"}>

Coercing an existing set

include Cassandra::Types

set(varchar).new(Set['Jane', 'Alice', 'Loren']) => #<Set: {"Jane", "Alice", "Loren"}>

Coercing an array

include Cassandra::Types

set(varchar).new(['Jane', 'Alice', 'Loren']) => #<Set: {"Jane", "Alice", "Loren"}>

Parameters:

  • value (Object)

    original value

Returns:

  • (Set)

    value

See Also:



885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'lib/cassandra/types.rb', line 885

def new(*value)
  value = value.first if value.one?

  case value
  when ::Array
    result = ::Set.new
    value.each do |v|
      Util.assert_type(@value_type, v)
      result << v
    end
    result
  when ::Set
    value.each do |v|
      Util.assert_type(@value_type, v)
    end
    value
  else
    Util.assert_type(@value_type, value)
    ::Set[value]
  end
end

#to_sString

Returns "set<type>".

Returns:

  • (String)

    "set<type>"

See Also:



924
925
926
# File 'lib/cassandra/types.rb', line 924

def to_s
  "set<#{@value_type.to_s}>"
end