親クラスの同名メソッドを呼ぶsuperについてです。
例えば以下のような場合
class User def login(acount, password) ~ログイン処理~ end end class AdminUser < User def login(password) ~ログイン処理~ ~固有の処理~ end end
AdminUserクラスではログインメソッドの中で、親クラスであるUserとログイン処理を共有しています。
同じ処理をなんども書きたくないので、親クラスのログインメソッドを呼びたい。そんなときに使うのがsuperです。
続きを読む