LoginSignup
100
98

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-02-06

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

文字列

内容 Ruby2.2.0 Golang Node(ES2015)
文字列長取得 String#length len(str) String.prototype.length
大小比較 String#<=> strings.Compare()
先頭比較 String#start_with? strings.HasPrefix String.prototype.startsWith()
末尾比較 String#end_with? strings.HasSuffix String.prototype.endsWith()
任意文字での分割 String#split strings.Split(), regexp.Split() String.prototype.split()
空白文字での分割 strings.Fields
文字列配列の結合 Array#join strings.Join() Array.prototype.join()
部分文字列 str[start..end] str[start:end] String.prototype.substr()
繰り返し String#* strings.Repeat() String.prototype.repeat()
置換 String#tr, String#tr!, String#gsub strings.Replace(), regexp.ReplaceAllString() String.prototype.replace()
包含判定 String#include? strings.Contains()
前後の空白除去 String#strip strings.TrimSpace() String.prototype.trim()
前後の任意文字除去 strings.Trim()
末尾改行削除 String#chomp, String#chomp!
埋め込み文字列 "#{hoge}" `${hoge}`
フォーマット Kernle.#sprintf, String % args fmt.Sprintf()
フォーマット出力 Kernle.#printf fmt.Printf()
標準出力 Kernel.#print fmt.Print() process.stdout.write()
標準出力(改行) Kernel.#puts fmt.Println() console.log(), process.stdout.write()
変数ダンプ Kernel.#p fmt.Printf("%v\n", obj) console.dir()
バイト列への変換 不要 []byte(string) new Buffer()
バイト列からの変換 不要 string(bytes) buf.toString()

配列

内容 Ruby2.2.0 Golang Node(ES2015)
配列の結合 self += other slice = append(slice, other...) Array.prototype.concat()
内容のクリア Array#clear
要素で埋める Array#fill Array.prototype.fill()
フィルタ Array#keep_if Array.prototype.filter()
各要素を処理(each) Array#each Array.prototype.forEach(), Array.prototype.map()
指定要素を含む? Array#include? Array.prototype.includes()
指定要素の最初の位置 Array#find_index Array.prototype.findIndex()
指定要素の最後の位置 Array.prototype.lastIndexOf()
先頭に要素追加(unshift) Array#unshift Array.prototype.unshift()
末尾に要素追加(push) Array#push, self += other slice = append(slice, elem) Array.prototype.push()
末尾から要素削除(pop) Array#pop Array.prototype.pop()
たたみ込み(reduce) Enumerable#inject Array.prototype.reduce(), Array.prototype.reduceRight()
リバース Array#reverse Array.prototype.reverse()
先頭から要素削除(shift) Array#shift Array.prototype.shift()
ソート Array#sort Array.prototype.sort()

プロセス

内容 Ruby2.2.0 Golang Node(ES2015)
CLI引数(引数のみ) Object::ARGV os.Args[1:] process.argv[2..]
CLI引数(自分自身の名前) __FILE__ os.Args[0] process.argv[1]
環境変数 ENV os.Getenv() process.env
カレントディレクトリ取得 Dir.getwd os.Getwd() process.cwd()
ホームディレクトリ取得 Dir.home os.homedir()
ホスト名取得 Socket.gethostname os.Hostname() os.hostname()
PID取得 Process.#pid os.Getpid() process.pid
OS名取得 runtime.GOOS process.platform
アーキテクチャ名取得 runtime.GOARCH process.arch
言語バージョン取得 Object::RUBY_VERSION runtime.Version() process.version
終了 kernel.#exit os.Exit() process.exit()
異常終了(コア) panic() process.abort()

子プロセス

内容 Ruby2.2.0 Golang Node(ES2015)
子プロセス実行&結果取得 `hoge` exec.Command().Output() child_process.exec()

ファイルシステム

内容 Ruby2.2.0 Golang Node(ES2015)
一括ファイル読み出し IO.read() ioutil.ReadFile() fs.readFile(), fs.readFileSync()
一括ファイル書き出し IO.write() ioutil.WriteFile() fs.writeFile(), fs.writeFileSync()
ファイル存在確認 FileTest.#exist? os.Stat() & os.IsExist() fs.stat(), fs.statSync()
ディレクトリ作成 Dir.mkdir os.Mkdir() fs.mkdir(), fs.mkdirSync()
ディレクトリ作成(mkdir -p) FileUtils.#makedirs os.MkdirAll()
ファイル削除 File.delete os.Remove() fs.unlink(), fs.unlinkSync()

JSON

内容 Ruby2.2.0 Golang Node(ES2015)
JSON生成 JSON.#generate json.Marshal() JSON.Stringify()
JSON復号 JSON.#parse json.Unmarshal() JSON.parse()

オブジェクト操作

内容 Ruby2.2.0 Golang Node(ES2015)
コピー(clone作成) Object#clone *1
メソッド一覧取得 Object#methods *1 *1
メンバー一覧取得 Object#instance_variables fmt.Printf("%+v\n", obj) *1

ライブラリ

内容 Ruby2.2.0 Golang Node(ES2015)
ロガー logger log
CLIオプション解析 optparse, getoptlong flag
100
98
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
100
98