From: Robert Klemme Date: 2013-04-11T23:44:32+09:00 Subject: Re: confusion with Struct class --047d7bdc0c4ef43bd204da16d2fc Content-Type: text/plain; charset=ISO-8859-1 On Thu, Apr 11, 2013 at 4:27 PM, Love U Ruby wrote: > Why does every time the has value getting changed,while the instance > variables values are not getting changed? > > > Customer = Struct.new(:name, :address, :zip) > joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) > > p joe.hash > p joe.object_id > > #-93880937 > #8577648 > > p joe.hash > p joe.object_id > > #275982710 > #8577648 > > p joe.hash > p joe.object_id > > #767998854 > #8577648 > > What the heck are you doing? irb(main):004:0> Customer = Struct.new(:name, :address, :zip) => Customer irb(main):005:0> joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) => # irb(main):006:0> 5.times { puts joe.hash } 1060632465 1060632465 1060632465 1060632465 1060632465 => 5 irb(main):007:0> 5.times { puts Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345).hash } 1060632465 1060632465 1060632465 1060632465 1060632465 => 5 robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --047d7bdc0c4ef43bd204da16d2fc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Thu, Apr 11, 2013 at 4:27 PM, Love U Ruby <= lists@ruby-forum.= com> wrote:
Why does every time the has value getting changed,while th= e instance
variables values are not getting changed?


Customer =3D Struct.new(:name, :address, :zip)
joe =3D Customer.new("Joe Smith", "123 Maple, Anytown NC&quo= t;, 12345)

p joe.hash
p joe.object_id

#-93880937
#8577648

p joe.hash
p joe.object_id

#275982710
#8577648

p joe.hash
p joe.object_id

#767998854
#8577648


What the heck = are you doing?

irb(main):004:0> Customer = =3D Struct.new(:name, :address, :zip)
=3D> Customer
irb(main):005:0> joe =3D Customer.new("Joe Smith", "123 M= aple, Anytown NC", 12345)
=3D> #<struct Customer name= =3D"Joe Smith", address=3D"123 Maple, Anytown NC", zip= =3D12345>
irb(main):006:0> 5.times { puts joe.hash }
1060632465
1060632465
1060632465
1060632465
10606= 32465
=3D> 5
irb(main):007:0> 5.times { puts Cust= omer.new("Joe Smith", "123 Maple, Anytown NC", 12345).h= ash }
1060632465
1060632465
1060632465
1060632= 465
1060632465
=3D> 5
=A0
robert


--
remember.guy do |as, oft= en| as.you_can - without end
http://blog.rubybestpractice= s.com/
--047d7bdc0c4ef43bd204da16d2fc--