Beginner to Ruby

Discussion in 'Ruby' started by Abhilash Nama, Dec 3, 2011.

  1. Hi,

    I am trying to learn to program using Ruby and I have downloaded the
    Ruby 1.93 installer. My first code is here:
    but, this doesn't seem to work when I put it in Interactive Ruby on my

    I would appreciate if someone could help me figure out why?


    Abhilash Nama, Dec 3, 2011
    1. Advertisements

  2. "Doesn't work" is quite vague. Can you be more precise, e.g. by posting
    the whole error message you experience?
    Marvin Gülker, Dec 3, 2011
    1. Advertisements

  3. It works just fine here, I don't see any see any reason why it shouldn't.

    | $ irb raw.rb
    | raw.rb(main):001:0> class Person
    | raw.rb(main):002:1> attr_accessor :name, :gender, :age
    | raw.rb(main):003:1> end
    | => nil
    | raw.rb(main):004:0>
    | raw.rb(main):005:0* person1 =
    | => #<Person:0x7ff067f626b0>
    | raw.rb(main):006:0> = "Abhilash Nama"
    | => "Abhilash Nama"
    | raw.rb(main):007:0> person1.gender = "Male"
    | => "Male"
    | raw.rb(main):008:0> person1.age = "30"
    | => "30"
    | raw.rb(main):009:0>
    | raw.rb(main):010:0* puts person1.ageraw.rb(main):010:0* raw.rb(main):010:0> 30
    | => nil

    Using puts in an irb session seems to mess up the output some. But it says 30 on the end the line.

    Using ruby, not irb, it just says "30".

    mfg, simon .... l
    Simon Krahnke, Dec 5, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.