我想知道私人和受保護的Ruby之間的區別,有很多來源,但他們通常只告訴我私人方法不能被繼承,但以許多不同的方式。保護和私人之間的區別
class Person
private
def hello
puts "hello"
end
end
class Student < Person
def initialize
hello
end
end
leo = Student.new
但是,這個非常簡單的例子證明了這種說法是錯誤的,私有方法被繼承和使用。此外,如果我在這裏將'private'更改爲'protected',它仍然會給我「hello」,同時創建leo變量。那麼公共和保護怎麼樣?
好的,告訴我哪個 – Leo
@Leo - http://www.amazon.co.uk/Ruby-Programming-Language-David-Flanagan/dp/0596516177/ref=sr_1_5?ie=UTF8&qid=1395244731&sr=8- 5&keywords = ruby – BroiSatse
@BroiSatse我已經添加了這本書的鏈接,如果你當然不介意的話:) –