Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rubyでワンライナー / One-liner on Ruby
Search
mather
March 13, 2020
Programming
510
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
83
SolidjsでLeacTion!を作り直しました / Rebuilt LeacTion! in Solid.js
mather
0
370
Webフレームワークの功罪 / Advantages and considerable point of Web Frameworks
mather
0
520
LeacTion!のアップデートとプチ勉強会へのいざない / Updates of LeacTion and Petit Meetup
mather
0
560
LeacTion!について / About LeacTion!
mather
0
370
認知と思考パターン / Cognition and Pattern
mather
1
340
「モデル」を考える / 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
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.4k
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
230
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
250
Kotlinの15年とServer-Side Kotlin
n_takehata
1
190
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
170
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
240
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
7.1k
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
330
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
300
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
110
Event is what happens
moro
2
2.7k
Getting Started with Vibe Coding
miccheng
0
140
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
500
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Building Applications with DynamoDB
mza
96
7.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
580
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
600
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
Documentation Writing (for coders)
carmenintech
77
5.6k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
460
How to make the Groovebox
asonas
2
2.5k
The Pragmatic Product Professional
lauravandoore
37
7.5k
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
ご清聴ありがとうございました