Skip to content

Commit

Permalink
Refactor equality. Hopefully more Ruby-like.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevoke committed Sep 11, 2014
1 parent 60eab97 commit c0a3b51
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/sgf/collection.rb
Expand Up @@ -11,17 +11,17 @@ def initialize
end

def each
gametrees.each { |game| game.each { |node| yield node } }
gametrees.each do |game|
game.each do |node|
yield node
end
end
end

# Compares a tree to another tree, node by node.
# Nodes must be the same (same properties, parents and children).
def == other_collection
one = []
two = []
each { |node| one << node }
other_collection.each { |node| two << node }
one == two
def == other
self.map { |node| node } == other.map { |node| node }
end

#Returns an array of the Game objects in this tree.
Expand Down Expand Up @@ -54,11 +54,9 @@ def node_count
end

def populate_game_array
games = []
@root.children.each do |first_node_of_tree|
games << SGF::Gametree.new(first_node_of_tree)
@root.children.map do |first_node_of_tree|
SGF::Gametree.new(first_node_of_tree)
end
games
end

def method_missing method_name, *args
Expand Down

0 comments on commit c0a3b51

Please sign in to comment.