Ruby On Rails 면접 질문과 답변
Question: What is Range?Answer:Range is a great way to declare continuous variables. You should use it to declare arrays and other types of collections. range1 = (1..4).to_a => [1, 2, 3, 4] puts range1 1 2 3 4 You can also create strings in this format and it fills in the interim values automatically. range2 = ('bar'..'bat').to_a
puts range2
bar
bas
batSince the end result of using range is an array you can also iterate over it just like any other array. range2.each do |str|
puts "In Loop #{str}"
end
This produces the result as shown below: In Loop bar In Loop bas In Loop bat |
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
도움이 되었나요? 예 아니요
Most helpful rated by users:
- What is Ruby On Rails?
- Why Ruby on Rails?
- Explain how (almost) everything is an object in Ruby.
- What are Gems and which are some of your favorites?
- How would you declare and use a constructor in Ruby?