Class: Struct
- Inherits:
-
Object
show all
- Defined in:
- lib/backports/2.3.0/struct/dig.rb,
lib/backports/2.0.0/struct/to_h.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.keyword_init? ⇒ Boolean
2
3
4
|
# File 'lib/backports/3.1.0/struct/keyword_init.rb', line 2
def Struct.keyword_init?
new(1) && false rescue true
end
|
Instance Method Details
#dig(key, *rest) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/backports/2.3.0/struct/dig.rb', line 3
def dig(key, *rest)
return self[key] if key.respond_to?(:to_int)
return nil unless respond_to?(key)
val = public_send(key)
return val if rest.empty? || val == nil
raise TypeError, "#{val.class} does not have #dig method" unless val.respond_to? :dig
val.dig(*rest)
end
|
3
4
5
6
7
|
# File 'lib/backports/2.0.0/struct/to_h.rb', line 3
def to_h
h = {}
self.class.members.each{|m| h[m.to_sym] = self[m]}
h
end
|