LoginSignup
4
3

More than 5 years have passed since last update.

define_method の中から super を呼ぶ方法

Posted at
module M
  def f
    "ok"
  end
end

class C
  include M

  define_method(:f) do
    super rescue $!              # => #<RuntimeError: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly.>
    method(:f).super_method.call # => "ok"
    super()                      # => "ok"
  end
end

C.new.f

試行錯誤しつつググったら、明示的に super に引数を渡せばいいようです。
(上記では引数がないことを明示)

参照
Module#define_methodとsuper
http://d.hatena.ne.jp/rubikitch/20080614/1213417931

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3