Why doesn't assigning a variable to an array yield expected results in Ruby? -


using irb, tested following:

c:\pickaxe>irb irb(main):001:0> list_of_strings = %w{ list of strings in array } => ["a", "list", "of", "strings", "in", "an", "array"] irb(main):002:0> a, b, c = list_of_strings => ["a", "list", "of", "strings", "in", "an", "array"] irb(main):003:0> => "a" irb(main):004:0> b => "list" irb(main):005:0> c => "of" irb(main):006:0> 

in other languages i've developed in setting a, b, c = d sets values of a, b , c equal d in entirety. here set successive elements in array.

i don't understand how or why works. shed light on issue?

that's how array assignment works in ruby. it's trying clever, little, assigning each indexed item of array variable on left-hand side of assignment =


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -