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
復習OptionSet
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Tomohiro Nishimura
December 26, 2016
Technology
0
300
復習OptionSet
Tomohiro Nishimura
December 26, 2016
Tweet
Share
More Decks by Tomohiro Nishimura
See All by Tomohiro Nishimura
レガシーシステム洗い出し大作戦
sixeight
0
1.7k
我々のRealmはどこからやってくるのか
sixeight
1
420
まだ見ぬAPIに思いを馳せて
sixeight
0
150
今年読んだまんが
sixeight
0
240
べんりな検索ワード
sixeight
0
270
Readable Width in action
sixeight
0
190
UIPreviewInteraction: Overview
sixeight
1
630
Accessing the Music Library
sixeight
1
2.9k
Web APIについての雑談
sixeight
0
420
Other Decks in Technology
See All in Technology
A4)シラバスを超えて語る、テストマネジメント
moritamasami
0
110
Phase05_ClaudeCode入門
overflowinc
0
1.1k
生成AIで速度と品質を両立する、QAエンジニア・開発者連携のAI協調型テストプロセス
shota_kusaba
0
350
スピンアウト講座03_CLAUDE-MDとSKILL-MD
overflowinc
0
650
品質を経営にどう語るか #jassttokyo / Communicating the Strategic Value of Quality to Executive Leadership
kyonmm
PRO
2
1k
Phase09_自動化_仕組み化
overflowinc
0
880
Copilot 宇宙へ 〜生成AIで「専門データの壁」を壊す方法〜
nakasho
0
140
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
2
13k
コンテキスト・ハーネスエンジニアリングの現在
hirosatogamo
PRO
6
700
めちゃくちゃ開発するQAエンジニアになって感じたメリットとこれからの課題感
ryuhei0000yamamoto
0
240
夢の無限スパゲッティ製造機 #phperkaigi
o0h
PRO
0
320
20260323_データ分析基盤でGeminiを使う話
1210yuichi0
0
160
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
92
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
76
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
160
Site-Speed That Sticks
csswizardry
13
1.1k
Side Projects
sachag
455
43k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
A better future with KSS
kneath
240
18k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
92
The browser strikes back
jonoalderson
0
820
Paper Plane (Part 1)
katiecoart
PRO
0
5.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Transcript
෮श0QUJPO4FU ؔϞόΠϧΞϓϦݚڀձ
JE4JYFJHIU w ג ͯͳΞϓϦέʔγϣϯΤϯδχΞ w ۙگ w יϏʔϧͱ͍͏ΠϕϯτͰ࣌ؒҿΈଓ͚ ͨΒඓਫ͕ࢭ·Βͳ͘ͳΓ·ͨ͠
None
0QUJPO4FU
త w Ϣʔβʔ͕ૢ࡞ՄೳͳॲཧΛࢦఆ͢Δ w ྫ͑ w ಡΜͰ͍͍͚Ͳɺॻ͖ࠐΉࣄͰ͖ͳ͍ͱ͔ w ฤूͰ͖Δ͚Ͳɺ৽ن࡞Ͱ͖ͳ͍ͱ͔
&OVNFSBUJPO enum Permission { case read case create case edit
case delete }
&OVNFSBUJPO let permissions: [Permission] = [.read, .create] func read() {
guard permissions.contains(.read) else { forbidden() return } showReadViewController() }
&OVNFSBUJPO w ϦιʔεͷύʔϛογϣϯͱϢʔβʔͷݖݶ w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ w ͞Βʹάϧʔϓຖʹݖݶ͕͋ͬͨΓ͢Δͱʜ let resourcePermissions:
[Permission] = [.read] let userPermissions: [Permission] = [.read, .create, .edit, .delete] resourcePermissions.filter { permission in return userPermissions.contains(permission) }
None
#JUXJTFPQFSBUJPO // _ _ _ _ delete edit create read
// 0 0 0 0 1 1 1 1 struct Permission { static let read: UInt8 = 0b00000001 static let create: UInt8 = 0b00000010 static let edit: UInt8 = 0b00000100 static let delete: UInt8 = 0b00001000 } 6*OUʹ໊લ͚ͭΔͱྑͦ͞͏ʜ
#JUXJTFPQFSBUJPO let permissions: UInt8 = Permission.read | Permission.create func read()
{ guard (permissions & Permission.read) != 0 else { forbidden() return } showReadViewController() }
#JUXJTFPQFSBUJPO w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ let resource: UInt8 = Permission.read let
user: UInt8 = Permission.read | Permission.create | Permission.edit | Permission.delete let currentPermission = resource & user
None
0QUJPO4FU struct Permission: OptionSet { let rawValue: UInt8 static let
read = Permission(rawValue: 1 << 0) static let create = Permission(rawValue: 1 << 1) static let edit = Permission(rawValue: 1 << 2) static let delete = Permission(rawValue: 1 << 3) }
0QUJPO4FU let permissions: Permission = [.read, .create] func read() {
guard permissions.contains(.read) else { forbidden() return } showReadViewController() }
4FU"MHFCSB func contains(Self) func insert(Self) func update(with: Self) func remove(Self)
func union(Self) func intersection(Self) func symmetricDifference(Self) func formUnion(Self) func formIntersection(Self) func formSymmetricDifference(Self)
4FU"MHFCSB let p: Permission = [.read, .create, .edit] let o:
Permission = [.edit, .delete] p //=> 0111 o //=> 1100 p.union(o) //=> 1111 p.intersection(o) //=> 0100 p.symmetricDifference(o) //=> 1011
0QUJPO4FU w ͜ͷϦιʔεʹରͯ͜͠ͷϢʔβʔ͕Մೳͳૢ࡞ ͳΜͳͷ͔ let resource: Permission = [.read] let
user: Permission = [.read, .create, .edit, .delete] let current: Permission = resource.intersection(user)
None
Γ͍ͨ if case Permission.read = userPermission { print("Can read") }
Γ͍ͨ switch userPermission { case Permission.read: print("Can Read") fallthrough case
Permission.create: print("Can Create") fallthrough case Permission.edit: print("Can edit") fallthrough case Permission.delete: print("Can delete") }
dPQFSBUPS extension Permission { static func ~=(lhs: Permission, rhs: Permission)
-> Bool { return rhs.contains(lhs) } }
None
༇շͳؒͨͪ
༇շͳؒͨͪ w 6*$POUSPM4UBUF w OPSNBM w EJTBCMFE w FUDʜ button.setTitle("དྷ",
for: .normal) button.setTitle("ؔϞό", for: [.highlighted, .selected]) button.setTitle("ΑΖ͘͠", for: .disabled)
Α͍͓Λ