0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ruby学習#13 Arrays

Posted at

Rubyの配列は、変数、数字、いろいろ混ぜ込みOK
friends = Array[1,"karen","Oscar"]

friends = Array["Kevin","karen","Oscar"]
puts friends[0]

"Kevin"
puts friends[-1]
"Oscar"
puts friends[-2]
"Karen"
puts friends[0,2]
"Kevin"
"Karen"
puts friends[0,3]
"Kevin"
"Karen"
"Oscar"

friends = Array["Kevin","karen","Oscar"]
friends[0] = "Dwight"
puts friends[0]

Dwight

friends = Array.new

friends[0] 0 "Michael"
friends[5] = "Holly"

puts friends

"Michael"

"Holly"

friends = Array["Kevin", "karen", "Oscar"]
puts friends.length()

3

puts friends.include? "Karen"

True
puts friends.include? "Karens"
False
puts friends.reverse()
Oscar
Karen
Kevin
friends = Array["Kevin", "karen", "Oscar","Andy"]

puts friends.sort()

Andy
Karen
Kevin
Oscar

friends = Array["Kevin", 1, "Oscar","Andy"]

puts friends.sort()

error (型が違うからソートできない)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?