我是Ruby的新手,所以我不确定我做错了什么或违反了什么。
我的示例中有两个类,Deliverable
和Pillar
。
支柱对象可以包含一个或多个可交付物。
class Deliverable
def initialize (name, state, pillar)
@name = name
@state = state
@pillarNumber = pillar
end
def getName
@name
end
def state
@state
end
def pillarNumber
@pillarNumber
end
end
class Pillar
def initalize (name, mine)
@name = name
@mine = mine
end
def getName
@name
end
def getDeliverable
@mine
end
def getDeliverableName
@mine.getName
end
end
aDel = Deliverable.new("Deliverable", 0, 1)
puts "Deliverable Name: " + aDel.getName
aPil = Pillar.new("Pillar", aDel)
puts "Pillar Name: " + aPil.getName + "\n"
当我运行此代码时,我收到此错误:
pillar.rb:46:in `initialize': wrong number of arguments (2 for 0) (ArgumentError)
from pillar.rb:46:in `new'
from pillar.rb:46:in `<main>'
关于我做错了什么建议?
答案 0 :(得分:0)
你拼错了Pillar
的构造函数的名字# ⇓ NOTE MISSED “i” HERE
def initialize (name, mine)