Learning Ruby

Main Question or Discussion Point

I'm learning how to program with Ruby and would like some brains to pick.

Here's the context:

class Run_Record
def initialize
@run_number=gets
@time=gets
##in the future this will be more complicated
end
def property(arg)
#????
end
end

new_run=Run_Record.new
p new_run.property(:run_number)

What do I write in #???? to get the last line to print the run number it gets from the initiation? It seems like there should be a simple way to do this, something that would work kind of like #{arg} inside of strings. I realize that I can accomplish the ultimate task by using the attr_reader method, but I'm curious about whether one could approach the problem this way.
 
Last edited:

Answers and Replies

Related Threads for: Learning Ruby

  • Last Post
Replies
1
Views
611
  • Last Post
Replies
0
Views
3K
  • Last Post
Replies
9
Views
1K
  • Last Post
Replies
4
Views
2K
Replies
3
Views
882
  • Last Post
Replies
3
Views
17K
  • Last Post
Replies
1
Views
2K
Replies
1
Views
508
Top