Multiple Assignment tricks
# Basic Usage
a, b, c = [1, 2, 3] # a = 1; b = 2; c = 3;
a, b, c = [1, 2] # a = 1; b = 2; c = nil;
# Advansed Usage
list = [1, 2, 3]
a, *b = list # a = 1; b = [2, 3];
*b, c = list # b = [2, 3]; c = 2;
Written by Andrew [8xx8] Kulakov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#