The following behavior looks like the assign method treats visited by value, while the append method treats it as a link:
class MyClass def assign(visited) visited += ["A"] end def append(visited) visited << "A" end end instance = MyClass.new visited = [] instance.assign(visited) visited
Can anyone explain this behavior?
It is not a question of whether Ruby supports by reference or is passed by value, but rather of the example below, and why the two methods that supposedly do the same thing exhibit different types of behavior.
ruby
Floating rock
source share