From: hanmac@... Date: 2015-12-11T06:20:53+00:00 Subject: [ruby-core:72049] [Ruby trunk - Bug #11803] NoMethodError when calling String#gsub Issue #11803 has been updated by Hans Mackowiak. first i dont think its a good idea in a to_s method to change the value of the object. otherwise you need to use @instance variables then it works: ~~~ruby class TestFail def initialize(word) @word = word end def to_s return unless @word @word.gsub(/a/, "") end def word @word end end ~~~ ---------------------------------------- Bug #11803: NoMethodError when calling String#gsub https://bugs.ruby-lang.org/issues/11803#change-55457 * Author: Anonymous * Status: Rejected * Priority: Normal * Assignee: Yukihiro Matsumoto * ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- Assigning the result of a call to String#gsub throws a NoMethodError. It seems to have to do with assigning the return value to a variable with the same name as the method returning the string gsub is called on. I've included short script which reproduces the issue. ---Files-------------------------------- test_fail.rb (164 Bytes) -- https://bugs.ruby-lang.org/