| Class | Origami::Dictionary |
| In: |
sources/parser/dictionary.rb
sources/parser/obfuscation.rb |
| Parent: | Hash |
Class representing a Dictionary Object. Dictionaries are containers associating a Name to an embedded Object.
| to_hash | -> | to_h |
| each_value | -> | each |
| to_h | -> | value |
Creates a new Dictionary.
| hash: | The hash representing the new Dictionary. |
# File sources/parser/dictionary.rb, line 47
47: def initialize(hash = {}, indirect = false)
48:
49: unless hash.is_a?(Hash)
50: raise TypeError, "Expected type Hash, received #{hash.class}."
51: end
52:
53: super(indirect)
54:
55: hash.each_key { |k|
56: self[k.to_o] = hash[k].to_o unless k.nil?
57: }
58:
59: end
# File sources/parser/dictionary.rb, line 123
123: def []=(key,val)
124:
125: unless key.is_a?(Symbol) or key.is_a?(Name)
126: fail "Expecting a Name for a Dictionary entry, found #{key.class} instead."
127: end
128:
129: key = key.to_o
130: if not val.nil?
131: val = val.to_o
132: super(key,val)
133:
134: val.parent = self
135:
136: val
137: else
138: delete(key)
139: end
140: end
# File sources/parser/dictionary.rb, line 111
111: def map!(&b)
112:
113: self.each_pair { |k,v|
114: self[k] = b.call(v)
115: }
116:
117: end
# File sources/parser/dictionary.rb, line 119
119: def merge(dict)
120: Dictionary.new(super(dict))
121: end
# File sources/parser/obfuscation.rb, line 117
117: def to_obfuscated_str
118: content = TOKENS.first + Obfuscator.junk_spaces
119: self.each_pair { |key, value|
120: content << Obfuscator.junk_spaces +
121: key.to_obfuscated_str + Obfuscator.junk_spaces +
122: value.to_obfuscated_str + Obfuscator.junk_spaces
123: }
124:
125: content << TOKENS.last
126: print(content)
127: end