Forum: Ruby on Rails Ruby question

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
997fc4f3de31e06ae679aa331bbd4fe6?d=identicon&s=25 jim (Guest)
on 2007-03-26 18:01
(Received via mailing list)
Pardon my noobiness, but I'm learning both Ruby and Ror at the same
time and am trying to understand Ruby a bit here.

Say I have:
class Ticket
  attr_accessor :venue, :date

  def Test
    @venue = "Some Venue"
    @date = "03/31/2007"

puts x.venue

puts x.venue
which outputs:
> aaa
> Some Venue
My question is:
Is the venue variable I'm referring to above, the same variable or are
they different?  Is my call to x.Test (which in turn sets @venue)
essentially overwriting the same :venue instance variable?  I'm just
trying to understand this a little better.

Ea70eaa0b3f7ec4a7e893a6105dfdd46?d=identicon&s=25 ruby lang (Guest)
on 2007-03-26 18:20
(Received via mailing list)
Irb tells all. They are the same object. Your call test over writes the
@venue for instance x and returns the @date value.

=> #<Ticket:0xb7c8aab0>
irb(main):010:0> x.venue="aa"
=> "aa"
irb(main):011:0> puts x.venue
=> nil
irb(main):012:0> x.Test
=> "03/31/2007"
irb(main):013:0> puts x.venue
Some Venus
=> nil
irb(main):014:0> x
=> #<Ticket:0xb7c8aab0 @venue="Some Venus", @date="03/31/2007">

Stephen Becker IV
This topic is locked and can not be replied to.