LoginSignup
2
0

More than 5 years have passed since last update.

[Ruby] チートシート 書きかけ

Last updated at Posted at 2018-07-19

文字列

文字列に変換

1.to_s
=> "1"

class名

'kotaro'.class == String
=> true

条件は式は値で判定される

'kotaro' == 'kotaro'
=>true

'kotaro' == String.new('kotaro')
=> true

文字列変換

# 文字列の先頭を大文字
'kotaro'.capitalize
=> "Kotaro"

配列

配列の変換

(1..10).to_a
=> [1, 2, .. 10]

配列の作成

%w[foo bar baz]
=> ["foo", "bar", "baz"]

ハッシュ

ハッシュの初期化

>> h = {}
>> h['foo']
=> nil

h = Hash.new(0)
>> h['foo']
=> 0

Range

(1..10) == Range(1, 10)
=> true

Ruby on Rails

2
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
2
0