Basic ruby error

Hi, all.

I'm attempting to learn Ruby & I'm using Apress's "Beginning Ruby".

The very first code example he gives in the book to run in Irb throws an
error:

`$ irb
1.9.3-p362 :001 > class Person
1.9.3-p362 :002?> attr_accessor :name, :age, :gender
1.9.3-p362 :003?> end
=> nil
1.9.3-p362 :004 > person_instance.name = "Robert"
NameError: undefined local variable or method `person_instance' for
main:Object
        from (irb):4
        from /Users/dobbin/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in
`<main>'`

which it appears it's complaining about the local variable that's been
assigned.

I've tried this with Ruby 1.9.3 & 2.1.0 but it's the same error.

Any help appreciated.

Cheers,

  Phil...

···

--
currently (ab)using
CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard,
RHEL 7, Ubuntu Precise & Saucy
GnuGPG Key : http://phildobbin.org/publickey.asc

after defining the class, you need to create the instance you are going to
use

so,

person_instance = Person.new

then use it

person_instance.name = ''Robert"

···

"ruby-talk" <ruby-talk-bounces@ruby-lang.org> wrote on 03/03/2014 07:44:48 AM:

From: Phil Dobbin <phildobbin@gmail.com>
To: ruby-talk@ruby-lang.org
Date: 03/03/2014 07:45 AM
Subject: Basic ruby error
Sent by: "ruby-talk" <ruby-talk-bounces@ruby-lang.org>

Hi, all.

I'm attempting to learn Ruby & I'm using Apress's "Beginning Ruby".

The very first code example he gives in the book to run in Irb throws an
error:

`$ irb
1.9.3-p362 :001 > class Person
1.9.3-p362 :002?> attr_accessor :name, :age, :gender
1.9.3-p362 :003?> end
=> nil
1.9.3-p362 :004 > person_instance.name = "Robert"
NameError: undefined local variable or method `person_instance' for
main:Object
        from (irb):4
        from /Users/dobbin/.rvm/rubies/ruby-1.9.3-p362/bin/irb:16:in
`<main>'`

which it appears it's complaining about the local variable that's been
assigned.

I've tried this with Ruby 1.9.3 & 2.1.0 but it's the same error.

Any help appreciated.

Cheers,

  Phil...

--
currently (ab)using
CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard,
RHEL 7, Ubuntu Precise & Saucy
GnuGPG Key : http://phildobbin.org/publickey.asc

[snip]

Please ignore last message. I'm an idiot :slight_smile:

Cheers,

  Phil...

···

On 03/03/2014 12:44, Phil Dobbin wrote:

Hi, all.

I'm attempting to learn Ruby & I'm using Apress's "Beginning Ruby".

--
currently (ab)using
CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard,
RHEL 7, Ubuntu Precise & Saucy
GnuGPG Key : http://phildobbin.org/publickey.asc

Thanks,

Cheers,

  Phil...

···

On 03/03/2014 12:52, HANSEM1@nationwide.com wrote:

after defining the class, you need to create the instance you are going
to use

so,

person_instance = Person.new

then use it

person_instance.name = ''Robert"

--
currently (ab)using
CentOS 6.5, Debian Squeeze & Wheezy, Fedora 19 & 20, OS X Snow Leopard,
RHEL 7, Ubuntu Precise & Saucy
GnuGPG Key : http://phildobbin.org/publickey.asc