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
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
100
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
540
ハイテク休憩
sat
PRO
2
150
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
MLOps の現場から
asei
6
640
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
560
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
470
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
We Have a Design System, Now What?
morganepeng
51
7.3k
4 Signs Your Business is Dying
shpigford
181
21k
Adopting Sorbet at Scale
ufuk
73
9.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Being A Developer After 40
akosma
87
590k
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