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 methodperson_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…

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” [email protected] wrote on 03/03/2014
07:44:48
AM:

On 03/03/2014 12:44, Phil D. wrote:

Hi, all.

I’m attempting to learn Ruby & I’m using Apress’s “Beginning Ruby”.

[snip]

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

Cheers,

Phil…

On 03/03/2014 12:52, [email protected] 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"

Thanks,

Cheers,

Phil…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs