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
20150625_SpeeeTeckParty
Search
Tatsuya Sasaki
June 30, 2015
Technology
9
8.7k
20150625_SpeeeTeckParty
6/25に開催された、SpeeeTeckPartyで話したときに資料です。
Tatsuya Sasaki
June 30, 2015
Tweet
Share
More Decks by Tatsuya Sasaki
See All by Tatsuya Sasaki
20180912_小さな成功体験を積み重ねてチームで負債に立ち向かう_medbeer.pdf
sasata299
3
11k
Classi - Real Tech Night
sasata299
1
4.3k
20151129_Mroongaをとある教育サービスで導入してみた話
sasata299
0
4.8k
前回のMF Geeks Nightに参加してから実践したこと
sasata299
0
860
20141125_エンジニアドリブンな改善の進め方
sasata299
0
2.1k
20140926_VagrantとDockerと普段思ってること
sasata299
2
5.3k
20140219_4社合同技術勉強会
sasata299
2
4.1k
AngularJSを使ったらこんなことが出来るよ
sasata299
40
71k
エンジニア異種クラスタ交流会01
sasata299
0
2.2k
Other Decks in Technology
See All in Technology
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
690
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
120
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
480
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
AGIについてChatGPTに聞いてみた
blueb
0
130
Engineer Career Talk
lycorp_recruit_jp
0
190
Featured
See All Featured
Being A Developer After 40
akosma
87
590k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Adopting Sorbet at Scale
ufuk
73
9.1k
The Pragmatic Product Professional
lauravandoore
31
6.3k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Writing Fast Ruby
sferik
627
61k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Ruby is Unlike a Banana
tanoku
97
11k
Code Reviewing Like a Champion
maltzj
520
39k
Fireside Chat
paigeccino
34
3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
What's in a price? How to price your products and services
michaelherold
243
12k
Transcript
3BJMT։ൃΛ͢Δ্Ͱ ͓͍ͬͯͨํ͕ྑͦ͞͏ͳ ̍̌ͷ͜ͱʢԾʣ 2015-06-25 @sasata299
ࣗݾհ w ͨͭ͞͞ w ώτϝσΟΞॴଐ w ͔Β͋͛ΤϯδχΞ w ٕज़ϒϩά
͔Β͋͛ ඒຯ͍͠
<13>ຊΛग़͠·ͨ͠
ͱ͍͏ࣄۀΛ͍ͬͯ·͢ɻ
ᶃ)BTIOFX\cI LcI<L>\^^ ᶄ'BU.PEFM ᶅ$PODFSO ᶆϓϨθϯςʔγϣϯ ᶇSBJMTDPOTPMFTBOECPY ᶈQMVDL ᶉpMUFS@QBSBNFUFST ᶊؔ࿈ͨ͠σʔλͷআ ᶋγϯάϧςʔϒϧܧঝʢ45*ʣ
ᶌJODMVEFͱQSFQFOE
ͬͱ͘ͱྑͦ͞͏ᶃ Hash.new { |h,k| h[k] = {} }
> hash = {} => {} > hash[:foo] => nil
> hash = Hash.new { |h,k| h[k] = {} }
=> {} > hash[:foo] => {} # nil͡Όͳ͍ʂ
> hash = Hash.new { |h,k| h[k] = {} }
=> {} > hash[:foo] => {} # nil͡Όͳ͍ʂ > hash[:foo][:bar] => nil > hash[:foo][:bar] = 1 => 1 > hash => { foo: { bar: 1 } }
ͬͱ͘ͱྑͦ͞͏ᶄ Fat Model
Fat Controller Fat Model ??? ୭͕௨Δಓ
Fat Controller Fat Model ??? ୭͕௨Δಓ ServiceΦϒδΣΫτ FormΦϒδΣΫτ, etc..
ͬͱ͘ͱྑͦ͞͏ᶅ Concern
ؔ৺ࣄΛͻͱ͔ͨ·Γʹͯ͠ཧ͢Δʂ
class Group before_save :set_default_name_if_need def post(comment); end end ! class
Message before_save :set_default_name_if_need def post(comment); end end ಉ͡Α͏ͳॲཧ͕͋Δ߹
module Commentable extend ActiveSupport::Concern ! included do before_save :set_default_name_if_need end
! def post(comment) Comment.create!(content: comment) end end
class Group include Commentable end ! class Message include Commentable
end εοΩϦ
ͬͱ͘ͱྑͦ͞͏ᶆ ϓϨθϯςʔγϣϯ
ϑϧωʔϜΛද͍ࣔͨ͠ʂ
module UserHelper def full_name(user) user.last_name + user.first_name end end VTFSΦϒδΣΫτΛ͢ͷΠέͯͳ͍
class User < ActiveRecord::Base def full_name last_name + first_name end
end 7JFXͰ͔͠Θͳ͍ͷʹϞσϧʹஔ͘ʁ
module UserDecorator def full_name last_name + first_name end end ྫ͑BDUJWF@EFDPSBUPSΛ͏
ͬͱ͘ͱྑͦ͞͏ᶇ $ rails console —sandbox
$ rails console —sandbox > user = User.first => #<User
id: 1, name: "sasata299", like: "karaage"> > user.like = "sushi" => "sushi" > u.save! => true
$ rails console —sandbox > user = User.first => #<User
id: 1, name: "sasata299", like: "karaage"> > user.like = "sushi" => "sushi" > u.save! => true > user = User.first => #<User id: 1, name: "sasata299", like: "sushi">
$ rails console > user = User.first => #<User id:
1, name: "sasata299", like: “karaage"> ࠶DPOTPMFΛ։͘ͱSPMMCBDL͞ΕͯΔ
$ rails console > user = User.first => #<User id:
1, name: "sasata299", like: “karaage"> > _ => #<User id: 1, name: "sasata299", like: “karaage"> ͪͳΈʹΞϯμʔείΞศརͰ͢
ͬͱ͘ͱྑͦ͞͏ᶈ pluck
ສ݅ͷ6TFSΛ༻ҙͯ͠JEͷҰཡΛऔಘ
Benchmark.bm 10 do |r| r.report “select” do User.select(:id).map(&:id) end r.report
“pluck” do User.pluck(:id) end end
user system total real select 16.290000 0.760000 17.050000 ( 20.753481)
pluck 4.350000 0.590000 4.940000 ( 6.712115) ഒҎ্͍ͧʂ
User.select(:id) [#<User id:1>, #<User id: 2>, …] ΦϒδΣΫτΛੜ NBQ JE
͢Δ [1, 2, …]
User.pluck(:id) [1, 2, …] ActiveRecordΦϒδΣΫτͷ ੜ͕ൃੜ͠ͳ͍͍ʂ
ͬͱ͘ͱྑͦ͞͏ᶉ filter_parameters
ͦͷ··ͩͱηΩϡΞͳใ͕ ϩάʹྲྀΕͯ͠·͏ʂʂʼʻ
Started POST "/users" Processing by UsersController#create as HTML Parameters: {"email"=>"
[email protected]
",
“password"=>"secret-value", “credit_card_number"=>"1111-2222-3333-4444"}
3BJMTBQQMJDBUJPODPOpHpMUFS@QBSBNFUFST <QBTTXPSE DSFEJU@DBSE@OVNCFS> pMUFS@QBSBNFUFSTΛઃఆ͢Δ
Started POST "/users" Processing by UsersController#create as HTML Parameters: {"email"=>"
[email protected]
",
"password"=>"[FILTERED]", “credit_card_number"=>"[FILTERED]"}
ͬͱ͘ͱྑͦ͞͏ᶊ ؔ࿈ͨ͠σʔλͷআ
class Blog < ActiveRecord::Base has_many :articles dependent: :destroy end #MPHΛআͨ͠Βؔ࿈͢Δ"SUJDMFআ͢Δ
EFMFUFͱEFTUSPZͷҧ͍ EFMFUF ୯७ʹ%&-&5&จ͕ൃߦ͞ΕΔ͚ͩ EFTUSPZ CFGPSF@EFTUSPZBGUFS@EFTUSPZ࣮ߦ͞ΕΔ EFQFOEFOUߟྀ͞ΕΔ
ͬͱ͘ͱྑͦ͞͏ᶋ γϯάϧςʔϒϧܧঝʢ45*ʣ
ྑ͘ࣅͨϞσϧҰͭͷςʔϒϧͰѻ͓͏ ! 'PPEϞσϧͱ%SJOLϞσϧྑ͘ࣅͯΔ͔Β QSPEVDUTςʔϒϧͰ·ͱΊͯѻ͓͏ʂతͳ
class Product < ActiveRecord::Base # typeΧϥϜΛ͍࣋ͬͯΔ͜ͱʂ end ! class Food
< Product; end class Drink < Product; end
Food.create! <#Food id: 1, type: "Food", …> ! 2.times {
Drink.create! } <#Drink id: 2, type: "Drink", …> <#Drink id: 3, type: "Drink", …>
mysql> SELECT id, type FROM products; ! +----+-------+ | id
| type | +----+-------+ | 1 | Food | | 2 | Drink | | 3 | Drink | +----+-------+
Food.all [#<Food id: 1, type: "Food", …>] ! Drink.all [#<Drink
id: 2, type: "Drink", …>, #<Drink id: 3, type: "Drink", …>] ! Product.all [#<Food id: 1, type: "Food", …>, #<Drink id: 2, type: "Drink", …>, #<Drink id: 3, type: "Drink", …>]
ͬͱ͘ͱྑͦ͞͏ᶌ include ͱ prepend
ҙͷϝιουΛੜ͍ͨ͠
class Bar include Foo end ! p Bar.ancestors # [Bar,
Foo, Object, …] #BSΫϥε͕༏ઌ͞ΕΔ
class Bar prepend Foo end ! p Bar.ancestors # [Foo,
Bar, Object, …] 'PPϞδϡʔϧ͕༏ઌ͞ΕΔ
JODMVEFͱQSFQFOEͷڍಈͷҧ͍ JODMVEF ݩͷΫϥεͷޙΖʹՃ͞ΕΔ ಉ໊ͷϝιουͷ߹ɺݩͷΫϥε͕༏ઌ͞ΕΔ QSFQFOE ݩͷΫϥεΑΓલʹՃ͞ΕΔ ಉ໊ͷϝιουͷ߹ɺϞδϡʔϧ͕༏ઌ͞ΕΔ
ᶃ)BTIOFX\cI LcI<L>\^^ ᶄ'BU.PEFM ᶅ$PODFSO ᶆϓϨθϯςʔγϣϯ ᶇSBJMTDPOTPMFTBOECPY ᶈQMVDL ᶉpMUFS@QBSBNFUFST ᶊؔ࿈ͨ͠σʔλͷআ ᶋγϯάϧςʔϒϧܧঝʢ45*ʣ
ᶌJODMVEFͱQSFQFOE
࠷ޙʹ
https://www.wantedly.com/companies/hitomedia ΤϯδχΞืूͯ͠·͢ʂ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ @sasata299