Rubyã§æ¢åã¡ã½ãããæ¡å¼µããããæ¡å¼µæ§ãæããããããããªæã®ããæ¹ã¡ã¢ã ä¾ã¨ã㦠Array#to_sã®æ¡å¼µãããã ç¶æ¿ã¯ã©ã¹ã§ã®ã¡ã½ãããªã¼ãã¼ã©ã¤ã Arrayã®ç¶æ¿ã¯ã©ã¹ã¨superã使ããArrayã使ããã¦ããä»ã®é¨åãå£ããªãã®ã§å®å ¨ã Array#to_sã®ããã«ãæ¬æ¥ãªãå¼æ°ãåããªãã¡ã½ãããå¼æ°ããã§ãªã¼ãã¼ã©ã¤ãããå ´åã¯ãsuper()ã¨æ示çã«å¼æ°ãªãã§å¼ã¶å¿ è¦ãããã class OreArray < Array def to_s(args) if args == :hello "extend!!!" else super() end end end a = OreArray.new([1,2,3]) p a.to_s #=> "[1, 2, 3]" p a.to_s(:hello) #=> "extend!!!" class Array alias_
{{#tags}}- {{label}}
{{/tags}}