[#71931] [Ruby trunk - Feature #11786] [Open] [PATCH] micro-optimize case dispatch even harder — normalperson@...

Issue #11786 has been reported by Eric Wong.

9 messages 2015/12/08

[ruby-core:72049] [Ruby trunk - Bug #11803] NoMethodError when calling String#gsub

From: hanmac@...
Date: 2015-12-11 06:20:53 UTC
List: ruby-core #72049
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/

In This Thread

Prev Next