This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grep VmSwap /proc/*/status | sort -n -k 2 -r | head | |
ps axfu | grep 対象プロセス |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat /proc/meminfo | grep Mem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 範囲指定で配列を作成 | |
arr = (1..5).to_a | |
# [1, 2, 3, 4, 5] | |
# 配列の値を更新 | |
arr[1] = 'a' | |
puts arr | |
# [1, "a", 3, 4, 5] | |
# 配列の値を削除 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fruits = { "apple" => 100, "orange" => 40, "mango" => 500, "melon" => 777, "grape" => 999 } | |
# valueが偶数の値を探索するメソッドです。 | |
# 最初に一致した一つだけを、戻り値として渡します。 | |
fruits.detect{ |key, value| value % 2 == 0 } | |
# 実行結果 | |
# ["apple", 100] | |
fruits.find{|key, value| value % 2 == 0} | |
# 実行結果 | |
# ["apple", 100] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 = { a: 1, b: 2, c: 3 } | |
h2 = { d: "taro", e: "jiro" } | |
h3 = h1.merge(h2) | |
puts h3 | |
# 実行結果 | |
# {:a=>1, :b=>2, :c=>3, :d=>"taro", :e=>"jiro"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = {a: 1, b: 2, c: 3, d: "taro", e: "jiro"} | |
h.delete(:a) | |
puts h | |
# 実行結果 | |
# {:b=>2, :c=>3, :d=>"taro", :e=>"jiro"} | |
h = {a: 1, b: 2, c: 3, d: "taro", e: "jiro"} | |
# valueが数字の値だけを削除します。 | |
h.delete_if{|key, value| value.kind_of?(Integer)} | |
puts h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = {a: 1, b: 2, c: 3} | |
puts h.length | |
# 実行結果 | |
# 3 | |
puts h.size | |
# 実行結果 | |
# 3 | |
puts h.count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1[:a] = 1 | |
h1[:b] = 2 | |
h1[:c] = 3 | |
puts h1[:b] | |
# 実行結果 | |
# 2 | |
h2["a"] = 4 | |
h2["b"] = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 空のhashを定義 | |
h1 = Hash.new | |
h2 = {} | |
# keyとvalueをセットして定義 | |
# シンボルでも文字列でも定義できる | |
h3 = {a: 1, b: 2, c: 3} | |
h4 = {"a" => 1, "b" => 2, "c" => 3} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 配列の宣言 | |
arr_1 = [1, 2, 3, 4, 5] | |
# 繰り返しの処理 | |
arr_1.each do |arr| | |
puts 'hi' | |
puts arr | |
end | |
# 実行結果 | |
# hi | |
# 1 |
OlderNewer