Ruby,Golang,ES2015比較チートシート

ごきげんよう、erukitiです。僕が大好きなGolang, ES2015(Node.js)及び、心の故郷Rubyの比較形式のチートシートを作成中です。Ruby, Golang, JavaScriptを好きな人、これらを複数使って混乱している人は是非ご活用ください。一気に作成するのはしんどいので、このURLにてチビチビ作っていきます。ストックした人には更新が飛ぶようにします。

## 文字列

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
文字列長取得|[String#length](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/length.html)|[len(str)](https://golang.org/pkg/builtin/#len)|[String.prototype.length](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/length)
大小比較|[String#<=>](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/=3c=3d=3e.html)|[strings.Compare()](https://golang.org/pkg/strings/#Compare)|
先頭比較|[String#start_with?](http://docs.ruby-lang.org/ja/2.2.0/class/String.html#I_START_WITH--3F)|[strings.HasPrefix](https://golang.org/pkg/strings/#HasPrefix)|[String.prototype.startsWith()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
末尾比較|[String#end_with?](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/end_with=3f.html)|[strings.HasSuffix](https://golang.org/pkg/strings/#HasSuffix)|[String.prototype.endsWith()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)|
任意文字での分割|[String#split](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/split.html)|[strings.Split()](https://golang.org/pkg/strings/#Split), [regexp.Split()](https://golang.org/pkg/regexp/#Regexp.Split)|[String.prototype.split()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/split)
空白文字での分割||[strings.Fields](https://golang.org/pkg/strings/#Fields)|
文字列配列の結合|[Array#join](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/join.html)|[strings.Join()](https://golang.org/pkg/strings/#Join)|[Array.prototype.join()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
部分文字列|[str[start..end]](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/=5b=5d.html)|str[start:end]|[String.prototype.substr()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
繰り返し|[String#*](http://docs.ruby-lang.org/ja/2.3.0/method/String/i/=2a.html)|[strings.Repeat()](https://golang.org/pkg/strings/#Repeat)|[String.prototype.repeat()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
置換|[String#tr](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/tr.html), [String#tr!](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/tr=21.html), [String#gsub](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/gsub.html)|[strings.Replace()](https://golang.org/pkg/strings/#Replace), [regexp.ReplaceAllString()](https://golang.org/pkg/regexp/#Regexp.ReplaceAllString)|[String.prototype.replace()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
包含判定|[String#include?](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/include=3f.html)|[strings.Contains()](https://golang.org/pkg/strings/#Contains)|
前後の空白除去|[String#strip](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/strip.html)|[strings.TrimSpace()](https://golang.org/pkg/strings/#TrimSpace)|[String.prototype.trim()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)
前後の任意文字除去||[strings.Trim()](https://golang.org/pkg/strings/#Trim)|
末尾改行削除|[String#chomp](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/chomp.html), [String#chomp!](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/chomp=21.html)||
埋め込み文字列|["#{hoge}"](http://docs.ruby-lang.org/ja/2.2.0/doc/spec=2fliteral.html#string)||[\`${hoge}\`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/template_strings)
フォーマット|[Kernle.#sprintf](http://docs.ruby-lang.org/ja/2.2.0/method/Kernel/m/sprintf.html), [String % args](http://docs.ruby-lang.org/ja/2.2.0/method/String/i/=25.html)|[fmt.Sprintf()](https://golang.org/pkg/fmt/#Sprintf)|
フォーマット出力|[Kernle.#printf](http://docs.ruby-lang.org/ja/2.2.0/method/Kernel/m/printf.html)|[fmt.Printf()](https://golang.org/pkg/fmt/#Printf)|
標準出力|[Kernel.#print](http://docs.ruby-lang.org/ja/2.2.0/method/Kernel/m/print.html)|[fmt.Print()](https://golang.org/pkg/fmt/#Print)|[process.stdout.write()](https://nodejs.org/api/process.html#process_process_stdout)
標準出力(改行)|[Kernel.#puts](http://docs.ruby-lang.org/ja/2.2.0/method/Kernel/m/puts.html)|[fmt.Println()](https://golang.org/pkg/fmt/#Println)|[console.log()](https://nodejs.org/api/console.html#console_console_log_data), [process.stdout.write()](https://nodejs.org/api/process.html#process_process_stdout)|
変数ダンプ|[Kernel.#p](http://docs.ruby-lang.org/ja/2.2.0/method/Kernel/m/p.html)|[fmt.Printf("%v\n", obj)](https://golang.org/pkg/fmt/#Sprintf)|[console.dir()](https://nodejs.org/api/console.html#console_console_dir_obj_options)
バイト列への変換|不要|[]byte(string)|[new Buffer()](https://nodejs.org/api/buffer.html#buffer_new_buffer_str_encoding)
バイト列からの変換|不要|string(bytes)|[buf.toString()](https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end)


## 配列

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
配列の結合|[self += other](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/=2b.html)|[slice = append(slice, other...)](https://golang.org/pkg/builtin/#append)|[Array.prototype.concat()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
内容のクリア|[Array#clear](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/clear.html)||
要素で埋める|[Array#fill](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/fill.html)||[Array.prototype.fill()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
フィルタ|[Array#keep_if](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/keep_if.html)||[Array.prototype.filter()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
各要素を処理(each) | [Array#each](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/each.html)||[Array.prototype.forEach()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach), [Array.prototype.map()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
指定要素を含む？|[Array#include?](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/include=3f.html)||[Array.prototype.includes()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
指定要素の最初の位置|[Array#find_index](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/find_index.html)||[Array.prototype.findIndex()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
指定要素の最後の位置|||[Array.prototype.lastIndexOf()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
先頭に要素追加(unshift)|[Array#unshift](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/unshift.html)||[Array.prototype.unshift()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
末尾に要素追加(push)|[Array#push](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/push.html), [self += other](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/=2b.html)|[slice = append(slice, elem)](https://golang.org/pkg/builtin/#append)|[Array.prototype.push()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
末尾から要素削除(pop)|[Array#pop](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/pop.html)||[Array.prototype.pop()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
たたみ込み(reduce)|[Enumerable#inject](http://docs.ruby-lang.org/ja/2.2.0/method/Enumerable/i/inject.html)||[Array.prototype.reduce()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce), [Array.prototype.reduceRight()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight)
リバース|[Array#reverse](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/reverse.html)||[Array.prototype.reverse()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
先頭から要素削除(shift)|[Array#shift](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/shift.html)||[Array.prototype.shift()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
ソート|[Array#sort](http://docs.ruby-lang.org/ja/2.2.0/method/Array/i/sort.html)||[Array.prototype.sort()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)

## プロセス

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
CLI引数(引数のみ)|[Object::ARGV](http://docs.ruby-lang.org/ja/2.2.0/method/Object/c/ARGV.html)|[os.Args[1:]](https://golang.org/pkg/os/#pkg-variables)|[process.argv[2..]](https://nodejs.org/api/process.html#process_process_argv)
CLI引数(自分自身の名前)|[\_\_FILE\_\_](http://docs.ruby-lang.org/ja/2.2.0/doc/spec=2fvariables.html#pseudo)|[os.Args[0]](https://golang.org/pkg/os/#pkg-variables)|[process.argv[1]](https://nodejs.org/api/process.html#process_process_argv)
環境変数|[ENV](http://docs.ruby-lang.org/ja/2.2.0/class/ENV.html)|[os.Getenv()](https://golang.org/pkg/os/#Getenv)|[process.env](https://nodejs.org/api/process.html#process_process_env)
カレントディレクトリ取得|[Dir.getwd](http://docs.ruby-lang.org/ja/2.2.0/method/Dir/s/getwd.html)|[os.Getwd()](https://golang.org/pkg/os/#Getwd)|[process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)
ホームディレクトリ取得|[Dir.home](http://docs.ruby-lang.org/ja/2.2.0/method/Dir/s/home.html)||[os.homedir()](https://nodejs.org/api/os.html#os_os_homedir)|
ホスト名取得|[Socket.gethostname](http://docs.ruby-lang.org/ja/2.2.0/method/Socket/s/gethostname.html)|[os.Hostname()](https://golang.org/pkg/os/#Hostname)|[os.hostname()](https://nodejs.org/api/os.html#os_os_hostname)|
PID取得|[Process.#pid](http://docs.ruby-lang.org/ja/2.1.0/method/Process/m/pid.html)|[os.Getpid()](https://golang.org/pkg/os/#Getgid)|[process.pid](https://nodejs.org/api/process.html#process_process_pid)
OS名取得||[runtime.GOOS](https://golang.org/pkg/runtime/#pkg-constants)|[process.platform](https://nodejs.org/api/process.html#process_process_platform)
アーキテクチャ名取得||[runtime.GOARCH](https://golang.org/pkg/runtime/#pkg-constants)|[process.arch](https://nodejs.org/api/process.html#process_process_arch)
言語バージョン取得|[Object::RUBY_VERSION](http://docs.ruby-lang.org/ja/2.2.0/method/Object/c/RUBY_VERSION.html)|[runtime.Version()](https://golang.org/pkg/runtime/#Version)|[process.version](https://nodejs.org/api/process.html#process_process_version)
終了|[kernel.#exit](http://docs.ruby-lang.org/ja/2.2.0/class/Kernel.html#M_EXIT)|[os.Exit()](https://golang.org/pkg/os/#Exit)|[process.exit()](https://nodejs.org/api/process.html#process_process_exit_code)
異常終了(コア)||[panic()](https://golang.org/pkg/builtin/#panic)|[process.abort()](https://nodejs.org/api/process.html#process_process_abort)

### 子プロセス

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
子プロセス実行＆結果取得|[\`hoge\`](http://docs.ruby-lang.org/ja/2.2.0/doc/spec=2fliteral.html#command)|[exec.Command()](https://golang.org/pkg/os/exec/#Command)[.Output()](https://golang.org/pkg/os/exec/#Cmd.Output)|[child_process.exec()](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)

## ファイルシステム

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
一括ファイル読み出し|[IO.read()](http://docs.ruby-lang.org/ja/2.2.0/method/IO/i/read.html)|[ioutil.ReadFile()](https://golang.org/pkg/io/ioutil/#ReadFile)|[fs.readFile()](https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback), [fs.readFileSync()](https://nodejs.org/api/fs.html#fs_fs_readfilesync_file_options)
一括ファイル書き出し|[IO.write()](http://docs.ruby-lang.org/ja/2.2.0/method/IO/s/write.html)|[ioutil.WriteFile()](https://golang.org/pkg/io/ioutil/#WriteFile)|[fs.writeFile()](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback), [fs.writeFileSync()](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options)
ファイル存在確認|[FileTest.#exist?](http://docs.ruby-lang.org/ja/2.2.0/method/FileTest/m/exist=3f.html)|[os.Stat()](https://golang.org/pkg/os/#Stat) & [os.IsExist()](https://golang.org/pkg/os/#IsExist)|[fs.stat()](https://nodejs.org/api/fs.html#fs_fs_stat_path_callback), [fs.statSync()](https://nodejs.org/api/fs.html#fs_fs_statsync_path)
ディレクトリ作成|[Dir.mkdir](http://docs.ruby-lang.org/ja/2.2.0/method/Dir/s/mkdir.html)|[os.Mkdir()](https://golang.org/pkg/os/#Mkdir)|[fs.mkdir()](https://nodejs.org/api/fs.html#fs_fs_mkdir_path_mode_callback), [fs.mkdirSync()](https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_mode)|
ディレクトリ作成(mkdir -p)|[FileUtils.#makedirs](http://docs.ruby-lang.org/ja/2.2.0/method/FileUtils/m/makedirs.html)|[os.MkdirAll()](https://golang.org/pkg/os/#MkdirAll)|
ファイル削除|[File.delete](http://docs.ruby-lang.org/ja/2.2.0/method/File/s/delete.html)|[os.Remove()](https://golang.org/pkg/os/#Remove)|[fs.unlink()](https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback), [fs.unlinkSync()](https://nodejs.org/api/fs.html#fs_fs_unlinksync_path)

## JSON

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
JSON生成|[JSON.#generate](http://docs.ruby-lang.org/ja/2.2.0/method/JSON/m/generate.html)|[json.Marshal()](https://golang.org/pkg/encoding/json/#Marshal)|[JSON.Stringify()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
JSON復号|[JSON.#parse](http://docs.ruby-lang.org/ja/2.2.0/method/JSON/m/parse.html)|[json.Unmarshal()](https://golang.org/pkg/encoding/json/#Unmarshal)|[JSON.parse()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)

## オブジェクト操作

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
コピー(clone作成)|[Object#clone](http://docs.ruby-lang.org/ja/2.2.0/method/Object/i/clone.html)||[*1](http://stackoverflow.com/questions/8206523/how-to-create-a-deep-copy-of-an-object-in-ruby)
メソッド一覧取得|[Object#methods](http://docs.ruby-lang.org/ja/2.2.0/method/Object/i/methods.html)|[*1](http://stackoverflow.com/questions/21397653/how-to-dump-methods-of-structs-in-golang)|[*1](http://stackoverflow.com/questions/4352997/how-to-list-the-functions-methods-of-a-javascript-object-is-it-even-possible)
メンバー一覧取得|[Object#instance_variables](http://docs.ruby-lang.org/ja/2.2.0/method/Object/i/instance_variables.html)|fmt.Printf("%+v\n", obj)|[*1](http://stackoverflow.com/questions/2934787/view-list-of-all-javascript-variables-in-google-chrome-console)


## ライブラリ

内容|Ruby2.2.0|Golang|Node(ES2015)
----|----|------|------------
ロガー|[logger](http://docs.ruby-lang.org/ja/2.2.0/library/logger.html)|[log](https://golang.org/pkg/log/)|
CLIオプション解析|[optparse](http://docs.ruby-lang.org/ja/2.2.0/library/optparse.html), [getoptlong](http://docs.ruby-lang.org/ja/2.2.0/library/getoptlong.html)|[flag](https://golang.org/pkg/flag/)|