Class: Ilp::Term
- Inherits:
-
Object
- Object
- Ilp::Term
- Defined in:
- lib/ruby-cbc/ilp/term.rb
Instance Attribute Summary collapse
-
#mult ⇒ Object
Returns the value of attribute mult.
-
#var ⇒ Object
Returns the value of attribute var.
Instance Method Summary collapse
- #*(mult) ⇒ Object
- #+(vars) ⇒ Object
- #-(vars) ⇒ Object
- #<=(vars) ⇒ Object
- #==(vars) ⇒ Object
- #>=(vars) ⇒ Object
- #coerce(num) ⇒ Object
-
#initialize(var, mult = 1) ⇒ Term
constructor
A new instance of Term.
- #to_s ⇒ Object
Constructor Details
#initialize(var, mult = 1) ⇒ Term
Returns a new instance of Term.
6 7 8 9 |
# File 'lib/ruby-cbc/ilp/term.rb', line 6 def initialize(var, mult = 1) @mult = mult @var = var end |
Instance Attribute Details
#mult ⇒ Object
Returns the value of attribute mult.
4 5 6 |
# File 'lib/ruby-cbc/ilp/term.rb', line 4 def mult @mult end |
#var ⇒ Object
Returns the value of attribute var.
4 5 6 |
# File 'lib/ruby-cbc/ilp/term.rb', line 4 def var @var end |
Instance Method Details
#*(mult) ⇒ Object
32 33 34 35 |
# File 'lib/ruby-cbc/ilp/term.rb', line 32 def *(mult) raise ArgumentError, 'Argument is not numeric' unless mult.is_a? Numeric Ilp::Term.new(@var, @mult * mult) end |
#+(vars) ⇒ Object
11 12 13 |
# File 'lib/ruby-cbc/ilp/term.rb', line 11 def +(vars) Ilp::TermArray.new(self) + vars end |
#-(vars) ⇒ Object
15 16 17 |
# File 'lib/ruby-cbc/ilp/term.rb', line 15 def -(vars) Ilp::TermArray.new(self) - vars end |
#<=(vars) ⇒ Object
23 24 25 |
# File 'lib/ruby-cbc/ilp/term.rb', line 23 def <=(vars) Ilp::TermArray.new(self) <= vars end |
#==(vars) ⇒ Object
19 20 21 |
# File 'lib/ruby-cbc/ilp/term.rb', line 19 def ==(vars) Ilp::TermArray.new(self) == vars end |
#>=(vars) ⇒ Object
27 28 29 |
# File 'lib/ruby-cbc/ilp/term.rb', line 27 def >=(vars) Ilp::TermArray.new(self) >= vars end |
#coerce(num) ⇒ Object
37 38 39 |
# File 'lib/ruby-cbc/ilp/term.rb', line 37 def coerce(num) [Ilp::TermArray.new(self), num] end |
#to_s ⇒ Object
41 42 43 44 45 |
# File 'lib/ruby-cbc/ilp/term.rb', line 41 def to_s str = "++-"[mult <=> 0] << " " str << mult.abs.to_s << " " if mult != 1 str << var.to_s end |