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
480
Rubyでワンライナー / One-liner on Ruby
mather
March 13, 2020
Tweet
Share
More Decks by mather
See All by mather
数学勉強会へのいざない
mather
0
48
SolidjsでLeacTion!を作り直しました / Rebuilt LeacTion! in Solid.js
mather
0
340
Webフレームワークの功罪 / Advantages and considerable point of Web Frameworks
mather
0
490
LeacTion!のアップデートとプチ勉強会へのいざない / Updates of LeacTion and Petit Meetup
mather
0
510
LeacTion!について / About LeacTion!
mather
0
340
認知と思考パターン / Cognition and Pattern
mather
1
300
「モデル」を考える / Think about "model"
mather
0
390
Shall we make a speech?
mather
0
250
Elmでライフゲーム / LifeGame in Elm
mather
1
1.1k
Other Decks in Programming
See All in Programming
朝日新聞のデジタル版を支えるGoバックエンド ー価値ある情報をいち早く確実にお届けするために
junkiishida
1
290
Head of Engineeringが現場で回した生産性向上施策 2025→2026
gessy0129
0
200
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
810
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
8
2.1k
社内規程RAGの精度を73.3% → 100%に改善した話
oharu121
12
6.6k
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
120
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.3k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
2.2k
AI巻き込み型コードレビューのススメ
nealle
2
2.4k
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
13
7.5k
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
480
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.2k
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.1k
Become a Pro
speakerdeck
PRO
31
5.8k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
140
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Navigating Team Friction
lara
192
16k
Facilitating Awesome Meetings
lara
57
6.8k
GitHub's CSS Performance
jonrohan
1032
470k
The browser strikes back
jonoalderson
0
740
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
77
Utilizing Notion as your number one productivity tool
mfonobong
3
240
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
ご清聴ありがとうございました