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
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
380
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
Lambdaと地方とコミュニティ
miu_crescent
2
370
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
380
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
65
11k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
KATA
mclloyd
29
14k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Embracing the Ebb and Flow
colly
84
4.5k
A designer walks into a library…
pauljervisheath
203
24k
Music & Morning Musume
bryan
46
6.2k
A Tale of Four Properties
chriscoyier
156
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
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