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 程序员出于某种原因认为这是一个坏主意。我的问题是是什么阻止我这样做?