Class: Factbase::Simplified

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/terms/simplified.rb

Overview

Simplified operands.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(operands) ⇒ Simplified

Returns a new instance of Simplified.



14
15
16
# File 'lib/factbase/terms/simplified.rb', line 14

def initialize(operands)
  @operands = operands
end

Instance Method Details

#uniqueObject

Removes duplicate operands



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/factbase/terms/simplified.rb', line 19

def unique
  strs = []
  ops = []
  @operands.each do |o|
    o = o.simplify
    s = o.to_s
    next if strs.include?(s)
    strs << s
    ops << o
  end
  ops
end