Open stefankroes opened 8 years ago
Update: In my more complex real-life scenario, the .dup
does seem to solve the problems
In my more complex scenario, I'm calling dup every time, which also fixes the bug.
require 'graph'
g = GraphViz.new :G, type: 'digraph'
options = { fontsize: 10 }
g.add_node 'A', options.dup
g.add_node 'B', options.dup
puts g.output canon: String
The problem must be that the label is added to the options hash, in-place, but only if there is no label key in the options hash yet.
Please consider the following code and output. Note that nodes A and B both have the same label (A). This is obviously unexpected behavior.
The following code does lead to the correct results:
However, the following variations do not:
To me, this is totally amazing but I'm sure there is some explanation.
Tried on multiple Ruby versions from 1.9.3 to 2.3.0.