Class: MiniKraken::Core::AnyValue
- Inherits:
-
Object
- Object
- MiniKraken::Core::AnyValue
- Defined in:
- lib/mini_kraken/core/any_value.rb
Overview
When MiniKraken successfully finds a solution but cannot associate a definite value to one or more logical variable(s), then it is useful to “assign” such unbound variable a placeholder that stands for any possible value. Following the practice of the “Reasoned Scheme” book, we associate a rank number to such a placeholder in order to distinguish arbitrary values from independent variables.
Instance Attribute Summary collapse
-
#rank ⇒ Integer
readonly
The rank number helps to differentiate independent variables.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare with another instance.
-
#initialize(aRank) ⇒ AnyValue
constructor
A new instance of AnyValue.
- #pinned?(_ctx) ⇒ Boolean
- #quote(_ctx) ⇒ AnyValue
-
#to_s ⇒ Object
Use same text representation as in “Reasoned Schemer” book.
Constructor Details
#initialize(aRank) ⇒ AnyValue
Returns a new instance of AnyValue.
17 18 19 |
# File 'lib/mini_kraken/core/any_value.rb', line 17 def initialize(aRank) @rank = aRank end |
Instance Attribute Details
#rank ⇒ Integer (readonly)
The rank number helps to differentiate independent variables.
14 15 16 |
# File 'lib/mini_kraken/core/any_value.rb', line 14 def rank @rank end |
Instance Method Details
#==(other) ⇒ Boolean
Compare with another instance.
24 25 26 27 28 29 30 31 32 |
# File 'lib/mini_kraken/core/any_value.rb', line 24 def ==(other) if other.is_a?(AnyValue) rank == other.rank elsif other.is_a?(Integer) rank == other elsif other.id2name =~ /_\d+/ rank == other.id2name.sub(/_/, '').to_i end end |
#pinned?(_ctx) ⇒ Boolean
40 41 42 |
# File 'lib/mini_kraken/core/any_value.rb', line 40 def pinned?(_ctx) false end |
#quote(_ctx) ⇒ AnyValue
45 46 47 |
# File 'lib/mini_kraken/core/any_value.rb', line 45 def quote(_ctx) self end |
#to_s ⇒ Object
Use same text representation as in “Reasoned Schemer” book. return [String]
36 37 38 |
# File 'lib/mini_kraken/core/any_value.rb', line 36 def to_s "_#{rank}" end |