some_string = "i love lamp"
another_string = "i love desk"
def some_string.lovehate
if match /love/
sub /love/, "hate"
elsif match /hate/
sub /hate/, "love"
end
end
puts some_string.lovehate # => "i hate lamp"
puts another_string.respond_to? :lovehate # => false
m = some_string.method(:lovehate).unbind
m.bind(another_string).call # fails
これは失敗します
singleton method called for a different object (TypeError)
つまり、Ruby プログラマーが何らかの理由でこれを悪い考えだと考えたことは明らかです。私の質問は、私がこれを行うのを妨げているのは何ですか?