class C1 #クラス名は大文字.
Pi = 3.14 #大文字で始まるのは定数.
@@foo_c = 0 #@@で始まるのはクラス変数. (=staticメンバ)
def initialize(arg) #newの時に呼ばれる.
print "initialize[" , @@foo_c , "]\n"
@foo = true #@で始まるのはインスタンス変数. (=メンバ変数)
@@foo_c = arg #@@で始まるのはクラス変数. (=staticメンバ)
end
def func1
print "func1\n"
end
end
$g_value = 0 #グローバル変数は$で始まる
hoge = C1.new(1)
hoge.func1
fuga = C1.new(2)
module M1 #モジュール.initializeを持たず、classにincludeされなければならない.
def funcm; print "funcm\n"; end
end
class C2 < C1 #継承
include M1 #moduleのinclude
end
print "----------\n"
hoge2 = C2.new(3)
hoge2.func1
hoge2.funcm
fuga2 = C2.new(4)