Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoy McCaffrey
3,333 PointsWhy 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...
1 Answer
rowend rowend
2,926 PointsIt 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.