[Ruby]メソッドに引数を使用するサンプル

2021年8月27日

書式
def メソッド名(引数1,…)
処理コード
end

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/ruby
#クラスSampleの定義
class Sample
#メソッド名(引数1,引数2,...)
def funcA(strA,strB,strC)
p "welcome "+strA + " " +strB +" in "+strC
end
end
#インスタンスを作成
cft = Sample.new
# funcAを呼び出す
cft.funcA("study","skill","arkgame")
#!/usr/bin/ruby #クラスSampleの定義 class Sample #メソッド名(引数1,引数2,...) def funcA(strA,strB,strC) p "welcome "+strA + " " +strB +" in "+strC end end #インスタンスを作成 cft = Sample.new # funcAを呼び出す cft.funcA("study","skill","arkgame")
#!/usr/bin/ruby
#クラスSampleの定義
class Sample

 #メソッド名(引数1,引数2,...)
  def funcA(strA,strB,strC)
   p  "welcome "+strA + " " +strB +" in "+strC    
 end
end

#インスタンスを作成
cft = Sample.new

# funcAを呼び出す
cft.funcA("study","skill","arkgame")

実行結果
“welcome study skill in arkgame"

Ruby

Posted by arkgame