Ruby

構文
%Q{字符串}
%q{字符串}
サンプルコード

#!/usr/bin/ruby# -*- coding: UTF-8 -*- ark1 = %Q{文字列(String)は、ダブルクォート(")または ...

Ruby

構文
#{文字列A +文字列B}
サンプルコード

#!/usr/bin/ruby# -*- coding: UTF-8 -*- x, y, z = 21, 33, 48puts "x の値は: #{ x }"pu ...

Ruby

説明
#{文字列変数名}
文字列(String)は、ダブルクォート(“)、またはシングルクォート(‘)で囲みます。
サンプルコード

#!/usr/bin/ruby# -*- cod ...

Ruby

■ Rubyのインストール方法
1.「rubyinstaller-devkit-2.6.6-2-x64.exe」をダブルクリックします。

2.「Ruby 2.6.6-2-x64 with MSYS2 License ...

Ruby

1.クラスの定義

class Sample def setAddr(str) @@addr = str end def getAddr() return @@addr endend

2.クラスのインスタンス作成
cf ...

Ruby

1.セミコロン(;)なし 使用例
puts “AA01\n”
puts “BB02\n”
puts “CC03\n”

2.セミ ...

Ruby

サンプルコード
a = 9; b = 2
puts “Result is #{ a * b }”

strN= “User007”
puts ̶ ...

Ruby

サンプルコード

tt = "002"if tt == "001" then print("aaa")elsif tt == "002" then print("bbb")else print("other value")end

Ruby

書式

unless conditional codeend

コード

#!/usr/bin/ruby# -*- coding: UTF-8 -*-x=1unless x>2 puts "x < 2" els ...

Ruby

書式
code if condition

コード
#!/usr/bin/ruby

$debug=1
print “test data\n” if $debug ...

Ruby

サンプルコード
citys = { Tokyo: 2001, Oosakay: 2002, Yokohama: 2003}
citys.each { |key, value| puts “#{key} =& ...

Ruby

書式
collection.each do |variable|
code
end

コード

#!/usr/bin/ruby ary = ary.each do |i| puts iend

...

Ruby

書式
Hash* ] or
Hash.new Hash.new(obj)
Hash.new { |hash, key| block }

サンプルコード

#!/usr/bin/ruby$, = ...

Ruby

サンプルコード
#!/usr/bin/ruby

H = Hash

puts “#{H}”
puts “#{H}”

実行結果
1 ...

Ruby

書式
配列名.reverse
使用例

#!/usr/bin/ruby#クラスSampleの定義class Sample #文字列先頭の文字を大文字 def funcB eleArr= #配列の値を出力 p ele ...

Ruby

書式
180度回転 配列名.reverse.map(&:reverse)
上下反転 配列名.reverse
使用例

#!/usr/bin/ruby#クラスSampleの定義class Sample ...

Ruby

書式
二次元配列名.push(値)
使用例

#!/usr/bin/ruby#クラスSampleの定義class Sample #文字列を出力 def testFunc cft=, ] p "二次配列の要素追加前" ...

Ruby

書式
1.配列名 <<値
2.配列名+=値
使用例

#!/usr/bin/ruby#クラスSampleの定義class Sample #文字列を出力 def testFunc cft= p " ...