Class: Postscript::Model::Literals::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/postscript/model/literals/dictionary.rb

Overview

Inline dictionary literal: << /Key (value) /Num 42 >>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries = {}) ⇒ Dictionary

Returns a new instance of Dictionary.



10
11
12
13
# File 'lib/postscript/model/literals/dictionary.rb', line 10

def initialize(entries = {})
  @entries = entries.dup.freeze
  freeze
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



8
9
10
# File 'lib/postscript/model/literals/dictionary.rb', line 8

def entries
  @entries
end

Instance Method Details

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



23
24
25
# File 'lib/postscript/model/literals/dictionary.rb', line 23

def ==(other)
  other.is_a?(Dictionary) && other.entries == @entries
end

#[](key) ⇒ Object



15
# File 'lib/postscript/model/literals/dictionary.rb', line 15

def [](key) = @entries[key]

#accept(visitor, ctx) ⇒ Object



19
20
21
# File 'lib/postscript/model/literals/dictionary.rb', line 19

def accept(visitor, ctx)
  visitor.visit_dictionary(self, ctx)
end

#each(&block) ⇒ Object



17
# File 'lib/postscript/model/literals/dictionary.rb', line 17

def each(&block) = @entries.each(&block)

#hashObject



28
29
30
# File 'lib/postscript/model/literals/dictionary.rb', line 28

def hash
  @entries.hash
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


16
# File 'lib/postscript/model/literals/dictionary.rb', line 16

def key?(key) = @entries.key?(key)