- #1
mellifluidic
- 2
- 0
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.
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: