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
870
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
新卒1年目、はじめてのアプリケーションサーバー【IBM WebSphere Liberty】
ktgrryt
0
130
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
1
16k
メールヘッダーを見てみよう
hinono
0
110
シフトライトなテスト活動を適切に行うことで、無理な開発をせず、過剰にテストせず、顧客をビックリさせないプロダクトを作り上げているお話 #RSGT2025 / Shift Right
nihonbuson
3
2.2k
商品レコメンドでのexplicit negative feedbackの活用
alpicola
2
370
テストを書かないためのテスト/ Tests for not writing tests
sinsoku
1
170
なぜfreeeはハブ・アンド・スポーク型の データメッシュアーキテクチャにチャレンジするのか?
shinichiro_joya
2
490
タイミーのデータ活用を支えるdbt Cloud導入とこれから
ttccddtoki
1
160
FODにおけるホーム画面編成のレコメンド
watarukudo
PRO
2
280
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
860
CDKのコードレビューを楽にするパッケージcdk-mentorを作ってみた/cdk-mentor
tomoki10
0
210
Visual StudioとかIDE関連小ネタ話
kosmosebi
1
380
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
Documentation Writing (for coders)
carmenintech
67
4.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Navigating Team Friction
lara
183
15k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Designing Experiences People Love
moore
139
23k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Mobile First: as difficult as doing things right
swwweet
222
9k
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