Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rubyでワンライナー / One-liner on Ruby
Search
mather
March 13, 2020
Programming
0
450
Rubyでワンライナー / One-liner on Ruby
mather
March 13, 2020
Tweet
Share
More Decks by mather
See All by mather
SolidjsでLeacTion!を作り直しました / Rebuilt LeacTion! in Solid.js
mather
0
300
Webフレームワークの功罪 / Advantages and considerable point of Web Frameworks
mather
0
440
LeacTion!のアップデートとプチ勉強会へのいざない / Updates of LeacTion and Petit Meetup
mather
0
460
LeacTion!について / About LeacTion!
mather
0
320
認知と思考パターン / Cognition and Pattern
mather
1
270
「モデル」を考える / Think about "model"
mather
0
370
Shall we make a speech?
mather
0
230
Elmでライフゲーム / LifeGame in Elm
mather
1
1k
Elmで関数型を意識する / Think functionally with Elm
mather
0
410
Other Decks in Programming
See All in Programming
データベースの技術選定を突き詰める ~複数事例から考える最適なデータベースの選び方~
nnaka2992
0
410
VitestのIn-Source Testingが便利
taro28
8
2.4k
flutter_kaigi_mini_4.pdf
nobu74658
0
150
2025年のz-index設計を考える
tak_dcxi
11
4.1k
20250426 GDGoC 合同新歓 - GDGoC のススメ
getty708
0
110
2025-04-25 GitHub Copilot Agent ライブデモ(スクリプト)
goataka
0
110
Improve my own Ruby
sisshiki1969
1
110
Golangci-lint v2爆誕: 君たちはどうすべきか
logica0419
1
250
Browser and UI #2 HTML/ARIA
ken7253
2
180
ぽちぽち選択するだけでOSSを読めるVSCode拡張機能
ymbigo
14
6.2k
Storybookの情報をMCPサーバー化する
shota_tech
2
1k
GitHub Copilot for Azureを使い倒したい
ymd65536
1
330
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
172
14k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.7k
Why Our Code Smells
bkeepers
PRO
336
57k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
Embracing the Ebb and Flow
colly
85
4.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Thoughts on Productivity
jonyablonski
69
4.6k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Code Reviewing Like a Champion
maltzj
523
40k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Transcript
Ruby でワンライナー 2020-03-13 Ruby みやざき #1 桑畑英資
⾃⼰紹介 self_introduction = { name: " 桑畑英資", age: 36, job:
" フリーランスエンジニア", fav_language: %w(Scala Elm Ruby), comment: <<-EOS.gsub(/^ */, ""), ⼤学のときにRuby を使う授業でRuby に触れて慣れ親しむ。 その後にJava などにも触れたが、 オブジェクト指向の⾔語としてはRuby の⽅が好きだった。 更にその後Scala を知ったので(以下略) 今でもツールの⽤途でRuby は触っている。 EOS twitter_id: "@mather314" }
ワンライナーとは One-liner、⼀⾏で動くコード Perl ではよくある話 シェルスクリプトでもよくある話 grep とか、 sed とか、 awk
とか、etc... 最近だと peco とかも使えるから可能性が広がって捗る 例: 空のディレクトリに .gitkeep を作るワンライナー for f in $(find . -type d -empty | grep -v '.git/') ; do echo "$f/.gitkeep" ; done (実際に実⾏するときは echo を touch にする)
Web フレームワークばかり使ってませんか? Ruby は汎⽤プログラミング⾔語です 当然ですがスクリプトとして利⽤できます REPL (irb, pry) mruby など組み込みにも利⽤されている
極端な例として今回はワンライナーを紹介 実は ruby コマンドにはいろいろな便利オプションがありま す -e : ⽂字列をスクリプトとして実⾏する -r :
ライブラリを読み込んで実⾏する (require) -n , -p : while gets; ... ; end のように囲んだ状 態で動作する 「それ Ruby じゃなくてもできるよ!」というツッコミは (知ってるので)無視します
単体で $ ruby -e 'puts "Hello,world!"' Hello,world! $ ruby -e
'puts [*1..10].shuffle.join(", ")' 2, 1, 4, 9, 10, 7, 6, 8, 5, 3
標準⼊⼒と $ cat lorem.txt Lorem ipsum dolor sit amet, consectetur
adipiscing elit, ... $ cat lorem.txt | ruby -e 'puts $<.read.split(" ") .map(&:capitalize).join(" ")' Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing Elit, ... $< : 標準⼊⼒をファイルとしてアクセスできる read の他、 each , readlines とかも便利。
ライブラリも使って $ seq 1 100 | ruby -r prime -n
-e 'puts $_ if Prime.prime?($_.to_i)' 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
ご清聴ありがとうございました