f



confusion with local variable assignment

When you write

a = b # error. As b is not defined as a method or local variable

But if you try - 

a = a or b = b, MRI parse it without error. How the `a` or `b` on the right side is allowed, where as I didn't define them earlier.

Thanks
0
Arup
4/11/2014 1:24:38 PM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

3 Replies
308 Views

Similar Articles

[PageSpeed] 8

On 11.04.2014 15:24, Arup Rakshit wrote:
> When you write
>
> a = b # error. As b is not defined as a method or local variable
>
> But if you try -
>
> a = a or b = b, MRI parse it without error. How the `a` or `b` on the
> right side is allowed, where as I didn't define them earlier.

There was recently a thread over at ruby-forum
https://www.ruby-forum.com/topic/4487093

	robert
0
Robert
4/11/2014 5:41:00 PM
On Friday, April 11, 2014 11:11:00 PM UTC+5:30, Robert Klemme wrote:
> On 11.04.2014 15:24, Arup Rakshit wrote:
> 
> > When you write
> 
> >
> 
> > a = b # error. As b is not defined as a method or local variable
> 
> >
> 
> > But if you try -
> 
> >
> 
> > a = a or b = b, MRI parse it without error. How the `a` or `b` on the
> 
> > right side is allowed, where as I didn't define them earlier.
> 
> 
> 
> There was recently a thread over at ruby-forum
> 
> https://www.ruby-forum.com/topic/4487093
> 
> 
> 
> 	robert

Hello Robert,

Thanks for the link. Is this mailing list is linked with Ruby forum ?
0
Arup
4/11/2014 5:51:00 PM
On 11.04.2014 19:51, Arup Rakshit wrote:

> Thanks for the link. Is this mailing list is linked with Ruby forum ?

_This_ is not a mailing list but a Usenet group.  The mailing list 
ruby-talk has a unidirectional link to the forum.  It used to be all one 
at some point but some gateways have been taken out of service.

Cheers

	robert


0
Robert
4/12/2014 8:38:20 AM
Reply:

Similar Artilces:

What? Assigning a session variable also assigns the local variable?
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is burns. Here is the code: $frank = "burns"; $_SESSION['frank'] = "black"; echo "DEBUG: frank's last name is is $frank"; What is coming into play here? I thought of register_globals but I thought that only dealt with GET, POST, REQUEST, etc. thecrow wrote: > Alright, what the hell is going on here? > > In the following code, I expect the printed ...

[ANN] Ruby-Locale-0.9.0 / Ruby-Locale for Ruby on Rails-0.1.0
Hi, I'm pleased to announce 2 new libraries for Localization. * Ruby-Locale-0.9.0 * Ruby-Locale for Ruby on Rails-0.1.0 = Website http://rubyforge.org/projects/locale http://www.yotabanana.com/hiki/ruby-locale.html http://www.yotabanana.com/hiki/ruby-locale-howto.html (HOWTO) http://www.yotabanana.com/localeapi/files/README.html (Sample Website) http://www.yotabanana.com/locale_rails_sample/ = Install $ gem install locale $ gem install locale_rails = Ruby-Locale-0.9.0 Ruby-Locale is the pure ruby library which provides basic APIs for localization. It aims to support all environ...

(local-variables/warning) Error in File local-variables
Hi below is the error message that I get when opening some verilog and systemC files with Xemacs on a Fedora 8 x86 machine I have no clue what all these errors mean. I guest it is related to my .init.el file. I just took a file that I used many years ago. I have include the complete file below too. Thanks for any hint. nike (1) (local-variables/warning) Error in File local-variables: Symbol's value as variable is void: compile-command Backtrace follows: verilog-modify-compile-command() run-hooks(verilog-modify-compile-command) # bind (force) hack-local-variables(...

Variable Variables ... Confused
I've read the newsgroups on this ... the PHP website and I'm still confused .... I am parsing a variable $howmany to a for / loop to print out multiple form fields with similar names ... for ($t = 1; $t < $howmany; ++$t) { print '<TR><TD>Enter field ' . $t . '</TD><TD><INPUT TYPE="text" NAME="field' . $t . '"></TD></TR>'; } .... So, assuming $howmany = 3 I get ... <TR><TD>Enter field 1</TD><TD><INPUT TYPE="text" NAME="field1"></TD></TR&g...

Assignment to a variable variable
Sometimes I want to assign a value to a variable whose name is a parameter. For example =E2=88=87 GetVar varname [1] slot=E2=86=90DIR=E2=8D=B3varname [2] =E2=8D=8Evarname,'=E2=86=90=E2=8E=95FREAD 1 slot' =E2=88=87 Line [2] is unpleasant, as execute often is. The awkward part is that the language forces me to execute a whole statement -- to artificially construct a character version of some code -- including the assignment arrow. Here's a proposed language enhancement that seems natural to me: (=E2=8D=8Evarname)=E2=86=90=E2=8E=95FREAD 1 slot Pro...

(local-variables/warning) File local-variables error: Symbol's value as variable is void: compile-command
Hi I get the following error message when I start my xemacs in a directory containing a desktop file (see below). (local-variables/warning) File local-variables error: Symbol's value as variable is void: compile-command I have tried starting xemacs with -init_debug but I did not get any further info. Thanks for any hint. GA ;;;;;;;;;;;;;;;;;;;;;;;;; desktop file begins here ;; -------------------------------------------------------------------------- ;; Desktop File for Emacs ;; -------------------------------------------------------------------------- ;; Created Wed A...

local variable referenced before assignment
I cannot make sense of what's happening here ... I'm getting the following error: initializing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time /home/john/Dropbox/Projects/python/scripts/src 29 referencing last modified time Traceback (most recent call last): File "/home/john/Dropbox/Projects/python/scripts/src/file-watch.py", line 42, in <module> time.sleep(10000) File "/home/john/Dropbox/Projects/python/scripts/src/file-watch.py", line 18, in handler if modifiedTime <> lastM...

Assigning a block to a variable in Ruby
I am new to Ruby and curious as to how you emulate the following Javascript snippet (example in Windows, hence the call to Echo) var a = function(p) {WScript.Echo(p)} bar(a); function bar(z) { z(1); WScript.Echo(z); } which would of course create an anonymous function, assign it to variable a, pass this as a parameter to function bar() and then evaluate the function with parameter 1, then attempt to print the function itself (which Javascript will do, printing the text of the block) I found Ruby quite intuitive until I tried a = {some block} and found that this of course doesn't...

ndefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y"
Hi everybody I have a serious problem and i need your help. i use embedded matlab function in simulink to generate some matrices which i use as input to other bloc on simulink. But i got this error while the simulation is running: Undefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y" My code is function y = fcn(u) Ap=[0.9580 0 0 0;0 0.9418 0 0;0 0 0.9048 0;0 0 0 0.9277]; Bp=[0.25 0;0.25 0;0 0.5;0 0.5]; Cp=[0.1678 0 0.9516 0;0 0.2329...

assigning a pointer the address of local variable
Suppose I have a code like this, #include <stdio.h> int *p; void foo(int); int main(void){ foo(3); printf("%p %d\n",p,*p); return 0; } void foo(int r){ int s=r+1; p=&s; } In most of the compilers I use (GCC, MSVC++, lcc..) this program runs allright printing an address and the correct value 4. But is it correct to assign a global pointer the address of a local variable which does not exist after the function has ended? "Sourav" <soura.jagat@gmail.com> writes: > Suppose I have a code like this, > > #include <stdio.h> > > ...

File local variables and function hack-one-local-variable in files.el
I put the following at the bottom of a file of source code (True Basic, http://www.truebasic.com/) ! Local Variables: ! mode: outline ! outline-regexp:"^! @+" ! End: and got an error message about lack of the prefix "! " for the line ! outline-regexp:"^! @+" Investigating, I found that the function hack-one-local-variable in files.el was jumping to the beginning of the buffer for that file when setting the mode. My version is XEmacs 21.4 (patch 8) "Honest Recruiter (Windows [3])" [Lucid] (i586-pc-win32) of Sun Jun 16 2002 on T...

UnboundLocalError: local variable referenced before assignment
I have following code : import os, time, re, pyodbc, Image, sys from datetime import datetime, date, time from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTFont import mkTable mkTable.mkTable() and then file mkTable.py located in same directory has : def mkTable(): global canvas canvas = canvas.Canvas(fname, pagesize=A4) ... and so on this gives me following traceback: Traceback (most recent call last): Fil...

local variable referenced before assignment #2
Quick question, probably quite a simple matter. Take the follow start of a method: def review(filesNeedingReview): for item in filesNeedingReview: (tightestOwner, logMsg) = item if (logMsg != None): for logInfo in logMsg.changed_paths: This generates the error: UnboundLocalError: local variable 'logMsg' referenced before assignment I thought I'd assigned it in the "(tightestOwner, logMsg) = item" line - so in the python interpreter complaining about the fact this assignment might not go well? Thanks! On 2007-10-25, Pete...

assigning macro variables in both local and remote
Hi all=2C I have a program that does part of its processing locally and part remotely= (using RSUBMIT). Ive set some variables locally using %LET=2C but I want the same variables = set to the same values in the remote session too. Is there some way of assi= gning variables in the remote session from the local session?=20 Thanks L_B SAS 9.1.3 SP4 XP-PRO "The beggar laughs in the face of the thief" _________________________________________________________________ View photos of singles in your area Click Here http://a.ninemsn.com.au/b.aspx?URL=3Dhttp%3A%2F%2Fdating%2Eninemsn%2Ecom%...

Web resources about - confusion with local variable assignment - comp.lang.ruby

Assignment - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

HootSuite Rolls Out HootSuite Assignments Google Chrome Extension
Social-media-management platform HootSuite announced the release of HootSuite Assignments , a browser extension for Google Chrome that enables ...

The Art Assignment (@artassignment) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here The Art Assignment @ artassignment ...

TeacherKit - Class Organizer, Teacher Planner, Gradebook, Assignment List, Attendance and Student 's ...
Get TeacherKit - Class Organizer, Teacher Planner, Gradebook, Assignment List, Attendance and Student 's Grade Tracker on the App Store. See ...

Assignments - Flickr - Photo Sharing!
106/365 As you can see, I have a lot to work on this weekend. All of my assignments are due on Monday, so time to get crackin'. Oh, and when ...

Fits and Starts - An Art Assignment - YouTube
A short routine assembled and edited for The Art Assignment (https://www.youtube.com/user/theartassignment), set to an original track by Son ...

Animal of the Day: Mittens the Hermaphroditic Cat to Get Gender Assignment Surgery
Meanwhile in Canada… A cat born with both male and female genitalia in Newfoundland is about to go under the knife. Mittens was found in the ...

School assignments go high-tech
How much do you help your kids with their school projects? How much do you help your kids with their school projects? Remember when the pinnacle ...

Students enlist MyMaster website to write essays, assignments
Students from almost every university in NSW are paying up to $1000 to have their essays written by a Sydney-based company, undermining the academic ...

Snow Sky confirms spring assignment as England stayer enters quarantine - DailyTelegraph Search Search ...
ONE of the leading fancies for the Melbourne Cup, top English stayer Snow Sky has been confirmed as heading to our shores after entering quarantine ...

Resources last updated: 1/27/2016 1:38:40 AM