I’m new at Ruby, and failing to Google this easy question:
What’s the normal way to obtain a list of numbers [1, 2, ..., n] in Ruby? In Haskell I just type [1..n], and I’m sure that this is easy in Ruby also, but I can’t guess it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
1..nis a Range in Ruby. You can convert it to an array using(1..n).to_aor the shorter form[*1..n].Depending on what you’re doing, using the Range directly might be more efficient.