Skip to content

Instantly share code, notes, and snippets.

@siannopollo
Created November 11, 2008 13:03
Show Gist options
  • Save siannopollo/23827 to your computer and use it in GitHub Desktop.
Save siannopollo/23827 to your computer and use it in GitHub Desktop.
# Here are the pertinent equality methods in the Space class. You can view the whole thing here:
# http://github.com/siannopollo/joshua_son_of_nun/tree/master/lib/joshua_son_of_nun/space.rb
def to_s
[row.to_s + column.to_s, orientation].compact * ' '
end
alias_method :inspect, :to_s
def ===(klass)
self.is_a?(klass)
end
def ==(other)
to_s == other.to_s
end
def eql?(other)
self == other
end
def equal?(other)
self.eql?(other) && other === self.class
end
# This doesn't work, and I'm assuming it is because of my equality methods in the Space class
it "should work as expected in an array" do
array_one = ['A1', 'B2', 'C3'].collect {|s| Space(s)}
array_two = ['A1', 'C3'].collect {|s| Space(s)}
(array_one - array_two).should == [Space('B2')]
(array_one & array_two).should == [Space('A1'), Space('C3')]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment