Navigation Menu

Skip to content

Commit

Permalink
Separate long method to short methods
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 23, 2015
1 parent 8556050 commit 19268ce
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/droonga/differ.rb
Expand Up @@ -19,21 +19,9 @@ class << self
def diff(a, b)
case a
when Hash
difference = {}
(a.keys + b.keys).uniq.each do |key|
unless a[key] == b[key]
difference[key] = diff(a[key], b[key])
end
end
difference
diff_hashes(a, b)
when Array
difference = {}
[a.size, b.size].max.times do |index|
unless a[index] == b[index]
difference[index] = diff(a[index], b[index])
end
end
difference
diff_arrays(a, b)
else
if a == b
nil
Expand All @@ -42,6 +30,26 @@ def diff(a, b)
end
end
end

def diff_hashes(a, b)
difference = {}
(a.keys + b.keys).uniq.each do |key|
unless a[key] == b[key]
difference[key] = diff(a[key], b[key])
end
end
difference
end

def diff_arrays(a, b)
difference = {}
[a.size, b.size].max.times do |index|
unless a[index] == b[index]
difference[index] = diff(a[index], b[index])
end
end
difference
end
end
end
end

0 comments on commit 19268ce

Please sign in to comment.