Class: Amigo::Solution

Inherits:
Object show all
Includes:
Hamster::Immutable
Defined in:
lib/amigo/solution.rb

Instance Method Summary collapse

Constructor Details

#initialize(variables, row) ⇒ Solution

Returns a new instance of Solution.



9
10
11
12
# File 'lib/amigo/solution.rb', line 9

def initialize(variables, row)
  @variables = variables
  @row = row
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)



41
42
43
# File 'lib/amigo/solution.rb', line 41

def method_missing(name, *args, &block)
  self[name]
end

Instance Method Details

#[](name) ⇒ Object

Raises:

  • (NameError)


18
19
20
21
# File 'lib/amigo/solution.rb', line 18

def [](name)
  return @row[name] if include?(name)
  raise NameError, "#{name.inspect} not found"
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/amigo/solution.rb', line 27

def eql?(other)
  return true if other.equal?(self)
  other.class.equal?(self.class) &&
    @variables.eql?(other.instance_variable_get(:@variables)) &&
    @row.eql?(other.instance_variable_get(:@row))
end

#hashObject



35
36
37
# File 'lib/amigo/solution.rb', line 35

def hash
  @variables.hash ^ @row.hash
end

#include?(name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/amigo/solution.rb', line 14

def include?(name)
  @variables.include?(name) && @row.has_key?(name)
end

#to_aryObject



23
24
25
# File 'lib/amigo/solution.rb', line 23

def to_ary
  @variables.map(@row).to_ary
end