From: Phrogz Date: 2007-01-27T09:20:06+09:00 Subject: Re: pass by reference? On Jan 26, 4:32 pm, Vincent Fourmond wrote: > You don't actually need to do anything: everything in ruby is passed > by reference, (excepted integers, symbols, nil, false and true - am I > missing one ?) How do you know if those are passed by reference or by value? It's a very existential question: If you pass an immutable type by reference, does it make a sound? Er, I mean... If you passed an immutable type by reference, how would you know that it wasn't passed by value? I leave you with this: irb(main):001:0> values = [ 1, :foo, true, false, nil ] => [1, :foo, true, false, nil] irb(main):002:0> puts values.map{ |v| v.object_id } 3 231138 2 0 4 => nil irb(main):003:0> def foo( *args ); puts args.map{ |v| v.object_id }; end => nil irb(main):004:0> foo( *values ) 3 231138 2 0 4 => nil irb(main):005:0> b = :foo => :foo irb(main):006:0> b.object_id => 231138 It's almost the reverse of what you said - it's not that immediate values are passed by value, but rather that every reference to an immediate value refers to the same object.