5/10æ¥ç®
å ¨5é¨ã®ãã¡ã®ç¬¬2é¨èªã¿çµãããã¯ã©ã¹ã¨ã¢ã¸ã¥ã¼ã«ã®é¨åãååã®éè¦ãã¤ã³ãããªã¼ã¨è¨ãæãããã®è¾ºã¯å°ãæãåããããããã
#!/usr/bin/ruby class AccTest def initialize(myname = 'instance name') @name = myname puts "\ninitialized by #{@name}" end public def pub puts "This is public method of #{@name}" # self.priv priv self.protec end private def priv puts "This is private method of #{@name}" end protected def protec puts "This is protected method of #{@name}" end end class AccTestTest < AccTest def pub_chld puts "This is public method of #{@name}" priv self.protec end end acc = AccTest.new acc.pub ruby = AccTest.new("ruby") ruby.pub acctesttest = AccTestTest.new("child") acctesttest.pub_chld # # initialized by instance name # This is public method of instance name # This is private method of instance name # This is protected method of instance name # # initialized by ruby # This is public method of ruby # This is private method of ruby # This is protected method of ruby # # initialized by child # This is public method of child # This is private method of child # This is protected method of child
ãã¾ãã¡ããã£ã¦ãªãã