Class: RBI::Rewriters::Merge
- Inherits:
-
Object
- Object
- RBI::Rewriters::Merge
- Extended by:
- T::Sig
- Defined in:
- lib/rbi/rewriters/merge_trees.rb
Overview
Merge two RBI trees together
Be this ‘Tree`: ~~~rb class Foo
attr_accessor :a
def m; end
C = 10
end ~~~
Merged with this one: ~~~rb class Foo
attr_reader :a
def m(x); end
C = 10
end ~~~
Compatible definitions are merged together while incompatible definitions are moved into a ‘ConflictTree`: ~~~rb class Foo
<<<<<<< left
attr_accessor :a
def m; end
=======
attr_reader :a
def m(x); end
>>>>>>> right
C = 10
end ~~~
Defined Under Namespace
Classes: Conflict, ConflictTreeMerger, Keep, TreeMerger
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(left_name: "left", right_name: "right", keep: Keep::NONE) ⇒ Merge
constructor
A new instance of Merge.
- #merge(tree) ⇒ Object
Constructor Details
#initialize(left_name: "left", right_name: "right", keep: Keep::NONE) ⇒ Merge
Returns a new instance of Merge.
70 71 72 73 74 75 76 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 70 def initialize(left_name: "left", right_name: "right", keep: Keep::NONE) @left_name = left_name @right_name = right_name @keep = keep @tree = T.let(MergeTree.new, MergeTree) @scope_stack = T.let([@tree], T::Array[Tree]) end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
67 68 69 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 67 def tree @tree end |
Class Method Details
.merge_trees(left, right, left_name: "left", right_name: "right", keep: Keep::NONE) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 54 def merge_trees(left, right, left_name: "left", right_name: "right", keep: Keep::NONE) left.nest_singleton_methods! right.nest_singleton_methods! rewriter = Rewriters::Merge.new(left_name: left_name, right_name: right_name, keep: keep) rewriter.merge(left) rewriter.merge(right) tree = rewriter.tree ConflictTreeMerger.new.visit(tree) tree end |
Instance Method Details
#merge(tree) ⇒ Object
79 80 81 82 83 |
# File 'lib/rbi/rewriters/merge_trees.rb', line 79 def merge(tree) v = TreeMerger.new(@tree, left_name: @left_name, right_name: @right_name, keep: @keep) v.visit(tree) @tree.conflicts.concat(v.conflicts) end |