Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Why does array = Array.new(3, "Jason") result in ["Jason", "Jason", "Jason"]?
At first glance, I assumed that the array would contain the integer 3 and the string "Jason" but then I realized it was using parentheses rather than brackets, so does that mean that when parenthesis are used on Array.new, if it has an integer than a string, the integer is determining the number of times the string belongs in the array? I guess that's described in the Ruby docs under common gotchas... but I don't think it was explained in the video...
rowend rowend2,926 Points
It was not explained in the video. But as you mention in docs you can find the new method can receive 2 parameters: The first type numeric will reflect the length of the array. The second will reflect the value to fill the array.