class Gamefic::Expression
A tokenization of an input from available syntaxes.
Attributes
tokens[R]
@return [Array<String>]
verb[R]
@return [Symbol]
Public Class Methods
new(verb, tokens)
click to toggle source
@param verb [Symbol, nil] @param tokens [Array<String>]
# File lib/gamefic/expression.rb, line 15 def initialize verb, tokens @verb = verb @tokens = tokens end
Public Instance Methods
compare(other)
click to toggle source
Compare two syntaxes for the purpose of ordering them by relevance while dispatching.
# File lib/gamefic/expression.rb, line 26 def compare other if verb == other.verb other.tokens.compact.length <=> tokens.compact.length else (other.verb ? 1 : 0) <=> (verb ? 1 : 0) end end
inspect()
click to toggle source
# File lib/gamefic/expression.rb, line 20 def inspect "#<#{self.class} #{([verb] + tokens).map(&:inspect).join(', ')}>" end