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
Block_is_everywhere.pdf
Search
Masafumi Okura
December 11, 2019
Programming
0
100
Block_is_everywhere.pdf
Masafumi Okura
December 11, 2019
Tweet
Share
More Decks by Masafumi Okura
See All by Masafumi Okura
Why did my proposals get rejected?
okuramasafumi
1
500
A suggestion for the future of RDoc
okuramasafumi
1
140
15 JSON serializers for Ruby
okuramasafumi
2
190
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
46
Creating gems 101
okuramasafumi
1
91
How NOT to make your DSL terrible
okuramasafumi
0
380
オブジェクトしこう
okuramasafumi
2
290
Debugging Alba
okuramasafumi
1
210
Learning Ruby
okuramasafumi
5
580
Other Decks in Programming
See All in Programming
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.3k
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
130
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
260
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
410
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
130
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
330
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
340
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
250
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
200
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
870
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
200
HTML/CSS超絶浅い説明
yuki0329
0
160
Featured
See All Featured
RailsConf 2023
tenderlove
29
960
Embracing the Ebb and Flow
colly
84
4.5k
The Cult of Friendly URLs
andyhume
78
6.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
550
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
112
50k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
340
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Writing Fast Ruby
sferik
628
61k
Transcript
Block is everywhere Event: LegalForce Ruby Meet Up #1 Date:
2019-12-11 Speaker: େխ࢙
pp self • ໊લɿେխ࢙ • ॴଐɿϑϦʔϥϯε • ΤσΟλɿVim • Α͍͘ΔίϛϡχςΟɿGrow.rbʢओ࠵ʣɺTama.rbͳͲ
RubyͷϒϩοΫૉΒ͍͠
RubyͷϒϩοΫͷΘΕํ
RubyͷϒϩοΫ͕ΘΕ͍ͯΔՕॴ • RailsͷϨΠΞτͷϨϯμϦϯάʢyieldʣ • ֤छgemͷઃఆʢconfigure doʣ • RakeFactoryBotʹද͞ΕΔDSL • Ϧιʔεͷཧ
• ϑοΫͷఆٛ • etc…
RailsͷϨΠΞτͷϨϯμϦϯά • ϨΠΞτϑΝΠϧͷதʹ͋Δ”yield”࣮ϒϩοΫΛධՁ͠ ͍ͯΔ • RailsͷϏϡʔʢςϯϓϨʔτʣ࠷ऴతʹRubyͱ࣮ͯ͠ߦ͞ ΕΔͷͰೖΕࢠΛ࣮ݱ͢ΔͷʹϒϩοΫΛωετ͍ͤͯ͞Δͱ ࢥΘΕΔ • Ұ൪ແҙࣝʹϒϩοΫΛ͍ͬͯΔՕॴͰʁ
֤छgemͷઃఆ • “configure do |config|”ͱ͔ͷΞϨવϒϩοΫΛ͍ͬͯΔ • ίϯϑΟάΦϒδΣΫτʹΞΫηε͢Δͷ͕ײతʹͰ͖Δ • ઃఆ͞ΕΔଆ”config =
Config.new; yield(config)”Έ͍ͨʹ ॻ͚Δ • ࣮ϒϩοΫΛ͏ඞཁͳ͍…ʁ
DSL • DSLΛ࣮͢ΔͷʹϒϩοΫʢͱ͍͏ΑΓProcΦϒδΣΫτ ͱ”instance_eval”ϝιουʣඞਢ • RSpecͩͱϒϩοΫΛ࣮ߦ͢Δͨͼʹಗ໊ΫϥεΛ࡞͍ͯͨ͠ Γ͢Δ • ʮϝλϓϩάϥϛϯάRubyʯͱ͍͏໊ஶΛಡΉͱΈ͕Θ͔Δ
Ϧιʔεͷཧ • “File.open do |f|”͕දత • “Net::HTTP.start do |http|”ͳΜ͔ͦ͏ •
ϝιου͕ϦιʔεΛ࡞͠ɺϒϩοΫ͕ด͡ΔͱϦιʔε ด͡ΒΕΔ
ϑοΫͷఆٛ • RSpecͷ”before(:each)”Railsͷ”before_action”ͳͲ͕දత • ϒϩοΫͷதΛProcΦϒδΣΫτͱͯ࣋ͪ͠ճ͢ • aroundܥͷϑοΫ෦ͰyieldΛݺͿͱຊॲཧ͕ΔͷͰೋ ॏʹϒϩοΫΛ͍ͬͯΔ
ଞʹ৭ʑͳϝιου͕ϒϩοΫΛड͚Δ • Enumerable#countʢϒϩοΫ͕trueͷཁૉΛ͑Δʣ • ActiveRecord::Relation#buildʢϒϩοΫͰΠϯελϯεઃఆʣ • Hash.newʢॳظԽͷํ๏Λنఆʣ • String#gsubʢஔͷํ๏Λنఆʣ
͓·͚
RubyͷϒϩοΫΫϩʔδϟ
पғͷڥʹΞΫηεͰ͖ΔͷͰɺ ৭ʑͱϋοΫ͢Δ͜ͱ͕Ͱ͖Δ
ྫɿΧϯλΦϒδΣΫτ