Class: Literal::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/literal/hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, key_type:, value_type:) ⇒ Hash

Returns a new instance of Hash.



4
5
6
7
8
# File 'lib/literal/hash.rb', line 4

def initialize(value, key_type:, value_type:)
	@value = value
	@key_type = key_type
	@value_type = value_type
end

Instance Attribute Details

#key_typeObject

Returns the value of attribute key_type.



10
11
12
# File 'lib/literal/hash.rb', line 10

def key_type
  @key_type
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/literal/hash.rb', line 10

def value
  @value
end

#value_typeObject

Returns the value of attribute value_type.



10
11
12
# File 'lib/literal/hash.rb', line 10

def value_type
  @value_type
end

Instance Method Details

#[]=(key, value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/literal/hash.rb', line 12

def []=(key, value)
	if @key_type === key && @value_type === value
		@value[key] = value
	else
		raise Literal::TypeError
	end
end