From: Mohammad Khan Date: 2005-01-20T01:10:22+09:00 Subject: Re: value by reference #!/usr/bin/env ruby def do_something(a, b, c) a += 1 b += 2 c += 3 end def another_do_something(foo=Foo.new) foo.do_something end class Foo def initialize @value = 0 end def value return @value end def value=(val) @value = val end def do_something @value += 1 @value += 2 @value += 3 end end a, b, c = 5, 6, 7 f = Foo.new # scenario 1 puts "before do_something : #{a.inspect}, #{b.inspect}, #{c.inspect}" do_something( a, b, c) puts "after do_something : #{a.inspect}, #{b.inspect}, #{c.inspect}" # a, b, c not changed #do_something( a.clone, b.clone, c.clone) #puts "after clone : #{a.inspect}, #{b.inspect}, #{c.inspect}" # can't clone Fixnum # scenario 2 puts "before : #{f.inspect}" another_do_something(f) puts "after with f : #{f.inspect}" # f changed another_do_something(f.clone) puts "after with f.clone : #{f.inspect}" # f not changed, it make sense What is the difference between scenario 1 and scenario 2? What is making scenario 1 not changed? If everything is object, Why can't I do do_something(a.clone, b.clone, c.clone) # I don't want them to be changed do_something(a, b, c) # change a, b, c like other objects Hope, I could explain properly what I am trying to understand. MOhammad