スーパークラスのprivateメソッドはサブクラスでも呼び出せる
irb(main):001* class Product
irb(main):002* private
irb(main):003*
irb(main):004* def name
irb(main):005* 'A great movie'
irb(main):006* end
irb(main):007> end
=> :name
irb(main):008* class DVD <Product
irb(main):009* def to_s
irb(main):010* "name:#{name}"
irb(main):011* end
irb(main):012> end
=> :to_s
irb(main):013> dvd = DVD.new
=> #<DVD:0x000000010bdc8168>
irb(main):014> dvd.to_s
=> "name:A great movie"
privateメソッドはオーバーライドできる
irb(main):001* class Product
irb(main):002* def to_s
irb(main):003* "name:#{name}"
irb(main):004* end
irb(main):005*
irb(main):006* private
irb(main):007*
irb(main):008* def name
irb(main):009* "A great movie"
irb(main):010* end
irb(main):011> end
=> :name
irb(main):012* class DVD < Product
irb(main):013* private
irb(main):014*
irb(main):015* def name
irb(main):016* "An awesome film"
irb(main):017* end
irb(main):018> end
=> :name
irb(main):019> pruoduct = Product.new
=> #<Product:0x000000010f344c10>
irb(main):021> pruoduct.to_s
=> "name:A great movie"
irb(main):022> dvd = DVD.new
=> #<DVD:0x000000010f37f108>
irb(main):023> dvd.to_s
=> "name:An awesome film"