Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page

Nested Assignments

Parallel assignments have one more feature worth mentioning. The left-hand side of an assignment may contain a parenthesized list of terms. Ruby treats these terms as if they were a nested assignment statement. It extracts out the corresponding rvalue, assigning it to the parenthesized terms, before continuing with the higher-level assignment.

b, (c, d), e = 1,2,3,4 b == 1, c == 2, d == nil, e == 3
b, (c, d), e = [1,2,3,4] b == 1, c == 2, d == nil, e == 3
b, (c, d), e = 1,[2,3],4 b == 1, c == 2, d == 3, e == 4
b, (c, d), e = 1,[2,3,4],5 b == 1, c == 2, d == 3, e == 5
b, (c,*d), e = 1,[2,3,4],5 b == 1, c == 2, d == [3, 4], e == 5

Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire