Remove/undef a class method

后端 未结 6 1360
滥情空心
滥情空心 2020-12-13 03:59

You can dynamically define a class method for a class like so:

class Foo
end

bar = %q{def bar() \"bar!\" end}
Foo.instance_eval(bar)

But h

6条回答
  •  不思量自难忘°
    2020-12-13 04:12

    I guess I can't comment on Adrian's answer because I don't have enough cred, but his answer helped me.

    What I found: undef seems to completely remove the method from existence, while remove_method removes it from that class, but it will still be defined on superclasses or other modules that have been extened on this class, etc.

提交回复
热议问题