# parameter passing example in Ruby def test1 a a = 10 print "in test1 -- a = " print a end def test2 a a[0] = 100 print "in test2 -- a = " print a end def test3 a a = [200] print "in test3 -- a = " print a end # try these examples # first a simple example of passing an integer # j = 5 # test1 j # afterwards j is still 5 # x = [1,2,3] # When we call test2, we pass the argument by value, but the value is # a reference to the array x. test2 assigns something to the 0th element # of its argument, and so x is changed. # test2 x # x # test3 on the other hand assigns a new array to its formal parameter, so # is unchanged # test3 x # x