32
respond_to?
을 정의하는 것과 반대로 respond_to_missing?
을 정의하는 요점은 무엇입니까? 어떤 수업에 respond_to?
을 다시 정의하면 어떻게됩니까? method
를 통해 방법을 얻으려고 노력 정의 respond_to_missing?
없이`respond_to?`vs.`respond_to_missing? '
respond_to?
을 정의하는 것과 반대로 respond_to_missing?
을 정의하는 요점은 무엇입니까? 어떤 수업에 respond_to?
을 다시 정의하면 어떻게됩니까? method
를 통해 방법을 얻으려고 노력 정의 respond_to_missing?
없이`respond_to?`vs.`respond_to_missing? '
는 실패합니다
class Foo
def method_missing name, *args
p args
end
def respond_to? name, include_private = false
true
end
end
f = Foo.new
f.bar #=> []
f.respond_to? :bar #=> true
f.method :bar # NameError: undefined method `bar' for class `Foo'
class Foo
def respond_to? *args; super; end # “Reverting” previous redefinition
def respond_to_missing? *args
true
end
end
f.method :bar #=> #<Method: Foo#bar>
Marc-André (루비 코어 커미터)
좋은 blog post onrespond_to_missing?
있습니다.
오, 좋은 답변입니다. 내가 지울거야. 새로운 것을 가르쳐 주셔서 감사합니다! – joelparkerhenderson
정보를 제공해 주셔서 감사합니다. – sawa
관심사에서, 그때를 위해'respond_to?'무엇이 좋은가. 합법적 인 유스 케이스가 있습니까? –