基本的にオタク向けのパズル:
クラスAがあり、1つのパラメーターを受け取るsaveメソッドがあり、パラメーターにはデフォルト値があります(trueとしましょう)。 パラメーターなしでsaveメソッドを受け入れるクラスAのインスタンスは、自動的にtrueを受け入れ、このフラグに従って動作します。 タイプAフィールドを持つクラスBがあります。パラメーターなしでクラスBのコンテキスト内からこのフィールドのsaveメソッドを呼び出す場合、制御はfalseパラメーターのデフォルト値を取る別のメソッド実装に転送する必要があります。 オーバーライドの仕組みについてですが、グローバルではなく、1つのクラス内のみです。
空白は次のとおりです。
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"
Copy Source | Copy HTML class A def save (validate = true ) validate ? "INVALID" : "VALID" end end class B # - def initialize @a = A .new end def save @a. save end end A . new . save # => "INVALID" B . new . save # => "VALID" A . new . save # => "INVALID"