Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
480
Rubyでワンライナー / One-liner on Ruby
mather
March 13, 2020
Tweet
Share
More Decks by mather
See All by mather
数学勉強会へのいざない
mather
0
38
SolidjsでLeacTion!を作り直しました / Rebuilt LeacTion! in Solid.js
mather
0
330
Webフレームワークの功罪 / Advantages and considerable point of Web Frameworks
mather
0
480
LeacTion!のアップデートとプチ勉強会へのいざない / Updates of LeacTion and Petit Meetup
mather
0
500
LeacTion!について / About LeacTion!
mather
0
330
認知と思考パターン / Cognition and Pattern
mather
1
280
「モデル」を考える / Think about "model"
mather
0
390
Shall we make a speech?
mather
0
250
Elmでライフゲーム / LifeGame in Elm
mather
1
1k
Other Decks in Programming
See All in Programming
AIコーディングエージェント(skywork)
kondai24
0
190
Deno Tunnel を使ってみた話
kamekyame
0
180
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
170
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
130
堅牢なフロントエンドテスト基盤を構築するために行った取り組み
shogo4131
8
2.4k
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
200
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
280
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.8k
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
230
愛される翻訳の秘訣
kishikawakatsumi
3
330
dotfiles 式年遷宮 令和最新版
masawada
1
800
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
0
290
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
29
The Mindset for Success: Future Career Progression
greggifford
PRO
0
180
Marketing to machines
jonoalderson
1
4.3k
The agentic SEO stack - context over prompts
schlessera
0
550
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
2
2.7k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
75
Code Reviewing Like a Champion
maltzj
527
40k
Design in an AI World
tapps
0
93
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.3k
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
ご清聴ありがとうございました