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
74
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
540
LeacTion!について / About LeacTion!
mather
0
360
認知と思考パターン / Cognition and Pattern
mather
1
320
「モデル」を考える / Think about "model"
mather
0
410
Shall we make a speech?
mather
0
270
Elmでライフゲーム / LifeGame in Elm
mather
1
1.1k
Other Decks in Programming
See All in Programming
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
220
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.4k
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
240
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
770
メールのエイリアス機能を履き違えない
isshinfunada
0
230
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
190
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
600
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Paper Plane (Part 1)
katiecoart
PRO
1
10k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
280
How to train your dragon (web standard)
notwaldorf
97
6.7k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
570
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
240
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
360
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
460
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
640
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
460
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
ご清聴ありがとうございました