Advertisement
Guest User

Untitled

a guest
May 6th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. # 基本形
  2. arr0 = ["a", "b", "c"]
  3.  
  4. # カンマのみならず, 改行でも要素を区切れる
  5. arr1 = [
  6. "a", "b", "c"
  7. "d", "e", "f"
  8. "g", "h", "i"
  9. ]
  10.  
  11. # カンマ+改行(任意回)でも一つの区切りとして認識
  12. # 最末尾にカンマを入れてもOK
  13. # カンマを複数回重ねるとNG
  14. arr2 = [
  15. "a", "b", "c",
  16. "d", "e", "f",
  17.  
  18. "g", "h", "i",
  19. # "j", "k", "l",,, <- NG
  20. ]
  21.  
  22. # 最初の要素は空白を開ける必要あり
  23. # 2個目以降は空けなくてもOK
  24. arr3 = [
  25. "a"
  26. "b"
  27. "c"
  28. ]
  29.  
  30. # 1から10までの配列
  31. arr4 = [1..10] # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  32.  
  33. # 逆向きも負の数もOK
  34. arr5 = [10..-1]
  35.  
  36. # 小数点もいけるけど1.0ずつ増えていくため末尾の数値が表示されないことがある
  37. arr6 = [0.1..3.0] # [0.1, 1.1, 2.1]
  38.  
  39. # 文字列は無理
  40. arr7 = ["a".."z"] # [ "a" ]
  41.  
  42. # booleanでもいけなくはない
  43. arr8 = [true..false] # [true, 0]
  44. arr9 = [false..true] # [false, 1]
  45. arr10 = [true..3] # [true, 2, 3]
  46. arr11 = [true..-3] # [true, 0, -1, -2, -3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement