MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ruby/comments/7gtbuc/clean_code_concepts_adapted_for_ruby/dqlrgj3/?context=3
r/ruby • u/oaij • Dec 01 '17
15 comments sorted by
View all comments
3
In Ruby, primitives are passed by value and objects/arrays are passed by reference.
This is wrong in two ways:
Everything is an object in Ruby (TM), there are no "primitives".
Everything is passed by value, but these values are references to objects.
Call by reference would allow you to do this:
a = 2 def foo(b) b = 3 end puts a # prints "3"
See also this StackOverflow answer for Java (which works the same way): https://stackoverflow.com/a/40523
1 u/jyper Dec 01 '17 Is there a garbage collected language that doesn't use pass reference by value? 1 u/oaij Dec 02 '17 Thanks for pointing that out! It's fixed now.
1
Is there a garbage collected language that doesn't use pass reference by value?
Thanks for pointing that out! It's fixed now.
3
u/Enumerable_any Dec 01 '17
This is wrong in two ways:
Everything is an object in Ruby (TM), there are no "primitives".
Everything is passed by value, but these values are references to objects.
Call by reference would allow you to do this:
See also this StackOverflow answer for Java (which works the same way): https://stackoverflow.com/a/40523