class Customer
@@no_of_customers=0
def initialize(id, name, addr)
@cust_id=id
@cust_name=name
@cust_addr=addr
end
end
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
我对 cust1=Customer.new 的理解是让对象 cust1 可以通过 "." 来使用 Customer类里面的方法,比如
cust1=Customer.new
cust1.initialize(a, b, c)
但为什么
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
可以这样直接传参数? 参数不应该都是穿给方法的么,如果一个类里有好几个方法,以上两段代码是什么意思呢??
@@no_of_customers=0
def initialize(id, name, addr)
@cust_id=id
@cust_name=name
@cust_addr=addr
end
end
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
我对 cust1=Customer.new 的理解是让对象 cust1 可以通过 "." 来使用 Customer类里面的方法,比如
cust1=Customer.new
cust1.initialize(a, b, c)
但为什么
cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya")
cust2=Customer.new("2", "Poul", "New Empire road, Khandala")
可以这样直接传参数? 参数不应该都是穿给方法的么,如果一个类里有好几个方法,以上两段代码是什么意思呢??