Skip to content

Commit

Permalink
hooks: remove superfluous #merge_arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Mar 14, 2015
1 parent 6a5ea78 commit fa40027
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/pry/hooks.rb
Expand Up @@ -56,18 +56,13 @@ def errors
# hooks = Pry::Hooks.new.add_hook(:before_session, :say_hi) { puts "hi!" }
# Pry::Hooks.new.merge!(hooks)
def merge!(other)
@hooks.merge!(other.dup.hooks) do |key, v1, v2|
merge_arrays(v1, v2)
@hooks.merge!(other.dup.hooks) do |key, array, other_array|
uniq_keeping_last(array + other_array, &:first)
end

self
end

def merge_arrays(array1, array2)
uniq_keeping_last(array1 + array2, &:first)
end
private :merge_arrays

def uniq_keeping_last(input, &block)
hash, output = {}, []
input.reverse.each{ |i| hash[block[i]] ||= (output.unshift i) }
Expand Down

0 comments on commit fa40027

Please sign in to comment.