「Ruby」クラスを定義するサンプル
書式
class クラス名
処理コード
end
使用例
#!/usr/bin/ruby
#クラスSampleの定義
class Sample
#メソッドの定義
def funcA
p "study skill many times"
end
end
#インスタンスを作成
cft = Sample.new
#関数を呼び出す
cft.funcA
実行結果
“study skill many times"
Coding Changes the World
書式
class クラス名
処理コード
end
使用例
#!/usr/bin/ruby
#クラスSampleの定義
class Sample
#メソッドの定義
def funcA
p "study skill many times"
end
end
#インスタンスを作成
cft = Sample.new
#関数を呼び出す
cft.funcA
実行結果
“study skill many times"