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
500
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rubyでワンライナー / One-liner on Ruby
mather
March 13, 2020
More Decks by mather
See All by mather
数学勉強会へのいざない
mather
0
75
SolidjsでLeacTion!を作り直しました / Rebuilt LeacTion! in Solid.js
mather
0
370
Webフレームワークの功罪 / Advantages and considerable point of Web Frameworks
mather
0
510
LeacTion!のアップデートとプチ勉強会へのいざない / Updates of LeacTion and Petit Meetup
mather
0
550
LeacTion!について / About LeacTion!
mather
0
370
認知と思考パターン / Cognition and Pattern
mather
1
330
「モデル」を考える / Think about "model"
mather
0
410
Shall we make a speech?
mather
0
280
Elmでライフゲーム / LifeGame in Elm
mather
1
1.1k
Other Decks in Programming
See All in Programming
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
5
1.8k
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.3k
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
170
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
590
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
180
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
530
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
170
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
Press start. Python's next generation.
willingc
PRO
3
280
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
320
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
260
Oxlintはいいぞ(続)
yug1224
1
490
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.5k
From π to Pie charts
rasagy
0
330
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
WENDY [Excerpt]
tessaabrams
12
39k
The SEO Collaboration Effect
kristinabergwall1
1
540
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Embracing the Ebb and Flow
colly
88
5.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
460
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
Rails Girls Zürich Keynote
gr2m
96
14k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.5k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
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
ご清聴ありがとうございました