Module#define_methodとsuper
define_methodの中にsuperを書くとどうなるか実験。
class A def hoge "hoge" end end class B < A define_method :hoge do "[#{super}]" end end class C < A define_method :hoge do "[#{super()}]" end end RUBY_VERSION # => "1.8.7" B.new.hoge rescue $! # => "[hoge]" C.new.hoge # => "[hoge]"
Ruby 1.8.7だと動く。
class A def hoge "hoge" end end class B < A define_method :hoge do "[#{super}]" end end class C < A define_method :hoge do "[#{super()}]" end end RUBY_VERSION # => "1.9.0" B.new.hoge rescue $! # => #<RuntimeError: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly.> C.new.hoge # => "[hoge]"
Ruby 1.9だと「super」はエラーで、明示的に引数をつけないといけないようだ。なんだろう……