From: mike@oobak.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71348] [Ruby trunk - Bug #11659] [Open] Strange behavior setting previously-undefined local variables with a statement modifier
Date: Thu, 05 Nov 2015 06:43:43 +0000 [thread overview]
Message-ID: <redmine.issue-11659.20151105064342.fe84e85dccc44a27@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11659.20151105064342@ruby-lang.org
Issue #11659 has been reported by Mike Pastore.
----------------------------------------
Bug #11659: Strange behavior setting previously-undefined local variables with a statement modifier
https://bugs.ruby-lang.org/issues/11659
* Author: Mike Pastore
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Consider a previously-undefined local variable `var1`:
~~~
irb(main):001:0> if defined?(var1).nil?; var1 = 'default'; end; var1
=> "default"
~~~
Consider previously-undefined local variables `var1` and `var2`:
~~~
irb(main):001:0> var2 = 'default' if defined?(var1).nil?; var2
=> "default"
~~~
Consider a previously-undefined local variable `var3`:
~~~
irb(main):001:0> var3 = 'default' if true; var3
=> "default"
~~~
Consider a previously-undefined local variable `var4`:
~~~
irb(main):001:0> var4 = 'default' if defined?(var4).nil?; var4
=> nil
~~~
Oops! Why is `var4` nil? Logically, considering the prior examples, it should be 'default'. Or are we missing something?
http://stackoverflow.com/questions/33537059/unless-defined-is-not-working-in-my-code
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2015-11-05 6:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-11659.20151105064342@ruby-lang.org>
2015-11-05 6:43 ` mike [this message]
2015-11-05 6:59 ` [ruby-core:71349] [Ruby trunk - Bug #11659] Strange behavior setting previously-undefined local variables with a statement modifier hanmac
2015-11-07 3:59 ` [ruby-core:71376] " mike
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-11659.20151105064342.fe84e85dccc44a27@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).