class Traitee::ConflictSolver
Attributes
conflicting_methods[R]
Public Class Methods
new(methods)
click to toggle source
# File lib/traitee/conflict_solver.rb, line 8 def initialize(methods) @methods = methods @conflicting_methods = {} end
Public Instance Methods
conflictless_method_map()
click to toggle source
# File lib/traitee/conflict_solver.rb, line 18 def conflictless_method_map @methods.reduce({}) do |res, map| res.merge!(map) { |method_name, method_a, method_b| solve_possible_conflict(method_name, method_a, method_b) } end end
method_in_conflict(method_name, method_a, method_b)
click to toggle source
# File lib/traitee/conflict_solver.rb, line 29 def method_in_conflict(method_name, method_a, method_b) conflict_solver = self @conflicting_methods[method_name] = [method_a, method_b] # define a method which raises an error - uncallable this.send(:define_method, method_name) do _method_a, _method_b = conflict_solver.conflicting_methods[method_name] fail MethodsInConflict.new "Modules are in conflict with method :#{method_name}" end this.instance_method(method_name) end
solve_possible_conflict(method_name, method_a, method_b)
click to toggle source
let it build, actual error will be raised later on all the usages of the method
# File lib/traitee/conflict_solver.rb, line 25 def solve_possible_conflict(method_name, method_a, method_b) method_a == method_b ? method_a : method_in_conflict(method_name, method_a, method_b) end
this()
click to toggle source
java reference :P, actual resolved module holder
# File lib/traitee/conflict_solver.rb, line 14 def this @this ||= Module.new end