Class: Factbase::Accum
- Inherits:
-
Object
- Object
- Factbase::Accum
- Defined in:
- lib/factbase/accum.rb
Overview
Accumulator of props.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(fact, props, pass) ⇒ Accum
constructor
Ctor.
- #method_missing(*args) ⇒ Object
-
#respond_to?(_method, _include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter.
- #respond_to_missing?(_method, _include_private = false) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(fact, props, pass) ⇒ Accum
Ctor.
35 36 37 38 39 |
# File 'lib/factbase/accum.rb', line 35 def initialize(fact, props, pass) @fact = fact @props = props @pass = pass end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/factbase/accum.rb', line 45 def method_missing(*args) k = args[0].to_s if k.end_with?('=') kk = k[0..-2] @props[kk] = [] if @props[kk].nil? @props[kk] << args[1] @fact.method_missing(*args) if @pass return end if k == '[]' kk = args[1].to_s vv = @props[kk].nil? ? [] : @props[kk] vvv = @fact.method_missing(*args) vv += vvv unless vvv.nil? vv.uniq! return vv.empty? ? nil : vv end return @props[k][0] unless @props[k].nil? @fact.method_missing(*args) end |
Instance Method Details
#respond_to?(_method, _include_private = false) ⇒ Boolean
rubocop:disable Style/OptionalBooleanParameter
67 68 69 70 |
# File 'lib/factbase/accum.rb', line 67 def respond_to?(_method, _include_private = false) # rubocop:enable Style/OptionalBooleanParameter true end |
#respond_to_missing?(_method, _include_private = false) ⇒ Boolean
72 73 74 |
# File 'lib/factbase/accum.rb', line 72 def respond_to_missing?(_method, _include_private = false) true end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/factbase/accum.rb', line 41 def to_s @fact.to_s end |