Custom + method in Ruby String

I am trying to modify the Ruby String class, specifically the + method. I want it to return a specific string such that

 "a" + "b" => "custom_result"

      

Here's what I have:

class String

  def +(a)
    "custom_result"
  end

end

      

When I try to request this file on irb, "custom_result" is in my prompt and I can't get anything done. Any ideas?

+3


source to share


1 answer


Well, IRb uses a class String

for both printing the results and parsing what you enter into it. If you mess around with this IRb breaks, no surprise.



+4


source







All Articles