class Cassandra::Types::Set

Attributes

value_type[R]

@private

Public Class Methods

new(value_type) click to toggle source

@private

Calls superclass method Cassandra::Type::new
    # File lib/cassandra/types.rb
774 def initialize(value_type)
775   super(:set)
776   @value_type = value_type
777 end

Public Instance Methods

==(other)
Alias for: eql?
assert(value, message = nil, &block) click to toggle source

Asserts that a given value is an Set @param value [Object] value to be validated @param message [String] error message to use when assertion fails @yieldreturn [String] error message to use when assertion fails @raise [ArgumentError] if the value is not an Set @return [void] @see Cassandra::Type#assert

    # File lib/cassandra/types.rb
826 def assert(value, message = nil, &block)
827   Util.assert_instance_of(::Set, value, message, &block)
828   value.each do |v|
829     Util.assert_type(@value_type, v, message, &block)
830   end
831   nil
832 end
eql?(other) click to toggle source
    # File lib/cassandra/types.rb
849 def eql?(other)
850   other.is_a?(Set) && @value_type == other.value_type
851 end
Also aliased as: ==
hash() click to toggle source
    # File lib/cassandra/types.rb
840 def hash
841   @hash ||= begin
842     h = 17
843     h = 31 * h + @kind.hash
844     h = 31 * h + @value_type.hash
845     h
846   end
847 end
new(*value) click to toggle source

Coerces the value to Set @param value [Object] original value @return [Set] value @see Cassandra::Type#new @example Creating a set using splat arguments

include Cassandra::Types

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

@example Coercing an existing set

include Cassandra::Types

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

@example Coercing an array

include Cassandra::Types

set(varchar).new(['Jane', 'Alice', 'Loren']) => #<Set: {"Jane", "Alice", "Loren"}>
    # File lib/cassandra/types.rb
797 def new(*value)
798   value = value.first if value.one?
799 
800   case value
801   when ::Array
802     result = ::Set.new
803     value.each do |v|
804       Util.assert_type(@value_type, v)
805       result << v
806     end
807     result
808   when ::Set
809     value.each do |v|
810       Util.assert_type(@value_type, v)
811     end
812     value
813   else
814     Util.assert_type(@value_type, value)
815     ::Set[value]
816   end
817 end
to_s() click to toggle source

@return [String] `“set<type>”` @see Cassandra::Type#to_s

    # File lib/cassandra/types.rb
836 def to_s
837   "set<#{@value_type}>"
838 end