code_junkie

Correct way to populate an Array with a Range in Ruby

Nov 11th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. warning: default `to_a' will be obsolete
  2.  
  3. irb> (1..4).to_a
  4. => [1, 2, 3, 4]
  5.  
  6. irb> 1..4.to_a
  7. (irb):1: warning: default `to_a' will be obsolete
  8. ArgumentError: bad value for range
  9. from (irb):1
  10.  
  11. 0..10.to_a
  12.  
  13. (0..10).to_a
  14.  
  15. >> a=*(1..10)
  16. => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  17.  
  18. Array (1..10)
  19. => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  20.  
  21. (1..10).to_a
  22. => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Add Comment
Please, Sign In to add comment