Class: Cassandra::Types::Map
- Inherits:
-
Cassandra::Type
- Object
- Cassandra::Type
- Cassandra::Types::Map
- Defined in:
- lib/cassandra/types.rb
Instance Attribute Summary
Attributes inherited from Cassandra::Type
Instance Method Summary collapse
-
#assert(value, message = nil, &block) ⇒ void
Asserts that a given value is a Hash.
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#new(*value) ⇒ Hash
Coerces the value to Hash.
-
#to_s ⇒ String
"map<type, type>"
.
Instance Method Details
#assert(value, message = nil, &block) ⇒ void
This method returns an undefined value.
Asserts that a given value is a Hash
726 727 728 729 730 731 732 733 |
# File 'lib/cassandra/types.rb', line 726 def assert(value, = nil, &block) Util.assert_instance_of(::Hash, value, , &block) value.each do |k, v| Util.assert_type(@key_type, k, , &block) Util.assert_type(@value_type, v, , &block) end nil end |
#eql?(other) ⇒ Boolean Also known as: ==
751 752 753 754 755 |
# File 'lib/cassandra/types.rb', line 751 def eql?(other) other.is_a?(Map) && @key_type == other.key_type && @value_type == other.value_type end |
#hash ⇒ Object
741 742 743 744 745 746 747 748 749 |
# File 'lib/cassandra/types.rb', line 741 def hash @hash ||= begin h = 17 h = 31 * h + @kind.hash h = 31 * h + @key_type.hash h = 31 * h + @value_type.hash h end end |
#new(*value) ⇒ Hash
Coerces the value to Hash
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/cassandra/types.rb', line 696 def new(*value) value = value.first if value.one? case value when ::Hash value.each do |k, v| Util.assert_type(@key_type, k) Util.assert_type(@value_type, v) end value when ::Array result = ::Hash.new value.each_slice(2) do |(k, v)| Util.assert_type(@key_type, k) Util.assert_type(@value_type, v) result[k] = v end result else raise ::ArgumentError, "cannot convert #{value.inspect} to #{self}" end end |
#to_s ⇒ String
Returns "map<type, type>"
.
737 738 739 |
# File 'lib/cassandra/types.rb', line 737 def to_s "map<#{@key_type}, #{@value_type}>" end |