我昨天开始使用Ruby并遇到问题。 我有两个课程:Patient和Patient_history。 患者可以有多个历史记录(来自不同的预约)。
这就是我现在所拥有的:
<ion-content *ngIf="page.pageName != 'MyPageWithUniqueToolbar'" class="no-scroll">
并且
class Patient
attr_accessor :name,
:surname,
:histories
def initialize(*)
@histories = []
end
def create_patient
@name = create_name_or_surname( "name")
@surname = create_name_or_surname("surname")
end
def create_name_or_surname( name_or_surname)
#not relevant in this case
end
def add_history(history)
@histories.push(history)
end
def print_patient
puts "name: #{@name}"
puts "surname : #{@surname}"
## I wish to do sth like:
## puts "history date: #{@histories[1].date}"
## to print content of Patient_history
end
end
有一条线: p病人 在设定历史和患者价值后,我得到:
class Patient_history
attr_accessor :date,
:description
def create_history
@date = create_date_or_desc("What is the date today?")
@description = create_date_or_desc("Write about an illness:")
end
end
你能告诉我一些该做什么吗?
答案 0 :(得分:0)
问题有点模糊,您是否希望打印出患者病史列表?您可以使用#each迭代每个历史记录。
def print_patient
puts "name: #{@name}"
puts "surname : #{@surname}"
histories.each do |history|
puts "History Date: #{history.date}"
puts history.description
end
end