Answer the question
In order to leave comments, you need to log in
Why are arrays printed the way they are?
Hello.
I'm JUST starting to learn Ruby and ran into 1 question that got me interested.
I don't fully understand how arrays are displayed. I have this code:
names = Array["George", "Bob", "Alex"]
names[0] = "Diana"
puts(names[0, 2])
Answer the question
In order to leave comments, you need to log in
Not specific indexes are specified through a comma, but an interval of indexes is set. The first number is the starting index, the second is how many elements to take. Read the documentation .
Array["George", "Bob", "Alex"]
George - 1 index
bob - 2
alex - 3
diana 0
from 0 to 2
0 - diana, 2 -
ruby bean is not pascal, here is the interval from which index to report
like this
names = Array["George", "Bob", "Alex"]
names[0] = "Diana"
puts(names[0, 3])
there is no problem until the problem becomes a real problem
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question