Ruby/チートシート

Ruby/チートシート

別の言語やってるとすぐに忘れるので。

バージョンと製造年月日

  • 2011-09-07
  • Ruby1.8.6

チートシート

コード慣例

2タブ,変数スネーク,クラスキャメル

変数

アルファベットでいきなり使える

関数
def hoge(a)
//return or 最終評価が戻る
end
配列

角括弧でズラズラ。foreachはeachメソッドにブロックドン

[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5].each do |a|
  p a
end
連想配列

rubyでの呼びはハッシュ。中括弧で矢印。キーにシンボルを使うことが多い

a = {'hoge' => 'ほげ', 'piyo' => 'ぴよ'}
b = {:hoge => 'ほげ', :piyo => 'ぴよ'}
forループ
5.times do
end
クラス
class Hoge < HogeSuper
  def initialize(hoge) #コンストラクタ
  end
  def a
  end
end
#new
hoge = Hoge.new("aaa")

タグ

ruby/cheat_sheet.txt · 最終更新: 2011-09-07 15:57 by ore