Class: Mailgunner::Struct
- Inherits:
-
Object
- Object
- Mailgunner::Struct
show all
- Defined in:
- lib/mailgunner/struct.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash = nil) ⇒ Struct
Returns a new instance of Struct.
5
6
7
|
# File 'lib/mailgunner/struct.rb', line 5
def initialize(hash = nil)
@hash = hash || {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
29
30
31
32
33
|
# File 'lib/mailgunner/struct.rb', line 29
def method_missing(name, *args)
return @hash[name.to_s] if @hash.key?(name.to_s)
super
end
|
Instance Method Details
#==(other) ⇒ Object
21
22
23
|
# File 'lib/mailgunner/struct.rb', line 21
def ==(other)
other.is_a?(self.class) && other.to_h == @hash
end
|
#[](key) ⇒ Object
9
10
11
|
# File 'lib/mailgunner/struct.rb', line 9
def [](key)
@hash[key.to_s]
end
|
#[]=(key, value) ⇒ Object
13
14
15
|
# File 'lib/mailgunner/struct.rb', line 13
def []=(key, value)
@hash[key] = value
end
|
#pretty_print(q) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/mailgunner/struct.rb', line 35
def pretty_print(q)
q.object_address_group(self) do
q.seplist(@hash, lambda { q.text ',' }) do |key, value|
q.breakable
q.text key.to_s
q.text '='
q.group(1) {
q.breakable ''
q.pp value
}
end
end
end
|
#respond_to_missing?(name, include_all) ⇒ Boolean
25
26
27
|
# File 'lib/mailgunner/struct.rb', line 25
def respond_to_missing?(name, include_all)
@hash.key?(name.to_s)
end
|
#to_h ⇒ Object
17
18
19
|
# File 'lib/mailgunner/struct.rb', line 17
def to_h
@hash
end
|