Issue #11103 has been updated by Recursive Madman.


Ruby is behaving as it should here. Your confusion is between local variables and method calls.
Before that 'if' block `mock_input` resolves to the "mock_input" *method* of your class. The 'if' block then declares a variable with the same name, shadowing the method.

----------------------------------------
Bug #11103: Reassignment in if block that is not ran, causes variable to become nil
https://bugs.ruby-lang.org/issues/11103#change-52262

* Author: Sigurd Berg Svela
* Status: Open
* Priority: High
* Assignee: 
* ruby -v: ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I came across a situation where, when reassigning a variable, inside an if statement that is evaluated to false, causes the variable to become nil.
I have included the code to reproduce the problem as a file.

Changing the line
<pre>variable = [variable]</pre>
to
<pre>@variable = [@variable]</pre>
seems to work as a temporary workaround, but this still seems to me as a pretty weird bug.

---Files--------------------------------
ruby-bug.rb (649 Bytes)


-- 
https://bugs.ruby-lang.org/