class Bogus::MakesDucks

Public Instance Methods

make(first_class, *classes) click to toggle source
# File lib/bogus/fakes/makes_ducks.rb, line 7
def make(first_class, *classes)
  duck = makes_subtypes.make(first_class)
  classes.each do |klass|
    method_copiers.each do |copier|
      remove_methods(copier.call(duck), copier.call(klass))
    end
  end
  duck
end

Private Instance Methods

remove_methods(duck_methods, klass_methods) click to toggle source
# File lib/bogus/fakes/makes_ducks.rb, line 19
def remove_methods(duck_methods, klass_methods)
  not_in_klass = duck_methods.all - klass_methods.all
  not_in_klass.each { |name| duck_methods.remove(name) }

  duck_methods.all.each do |name|
    duck_method = duck_methods.get(name)
    klass_method = klass_methods.get(name)
    unless same_interface?(duck_method, klass_method)
      duck_methods.remove(name)
    end
  end
end
same_interface?(method1, method2) click to toggle source
# File lib/bogus/fakes/makes_ducks.rb, line 32
def same_interface?(method1, method2)
  method1.parameters == method2.parameters
end