When we have to call a function with parameters there are basically two most generally known and easy to understand approaches for passing of parameters among all programming languages and these are pass-by-value and pass-by-reference. Ruby is pass-by-value, that is the direct answer. similar what java does.
Lets take a simple example:
def test(str)
str = 'reference'
end
str1 = 'value'
test(str1)
puts "Ruby is pass-by-#{str1}"
Method arguments are passed by value rather than by reference, but the values passed are object reference.
Because object reference are passed to method, method can use those reference to convert the basic object. These conversions are visible when the method returns.
0 Comment(s)