Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fjorb Boot Camp as a Gate

Fjorb Boot Camp as a Gate

(Show Noteは後日更新します)

Shintaro Kakutani

September 10, 2020
Tweet

More Decks by Shintaro Kakutani

Other Decks in Technology

Transcript

  1. Ruby “The State of the Octoverse”, Top languages section, GitHub

    https://octoverse.github.com/#top-languages
  2. ͪΐͬͱ3VCZΛॻ͍ͯΈΑ͏͔ɻ࢓༷ wϘʔφεͷֹۚΛࢉग़͢ΔΑ ͜Ε͸ՍۭͷྫͰ͋Γ࣮ࡏͷਓ෺ஂମͱ͸ SZ wڅ༩άϨʔυ͝ͱʹج४ֹ͕ۚ͋ΔΑ 4ϥϯΫ ສԁ "ϥϯΫ ສԁ #ϥϯΫ

    ສԁ  wύϑΥʔϚϯεϨϏϡʔͷ݁ՌͰϘʔφε͸૿ݮ͢Δ ༏ल ສԁϓϥε ;ͭ͏ Մࢉͳ͠ ࢒೦ ϚΠφεʜ આ໌༻ͷίʔυ͔ͩΒɺ͜Ε͕ʮਖ਼͍͠ʯॻ͖ํ͡Ό͋ͳ͍Α
  3. require_relative 'fjord_works' RSpec.describe 'ϘʔφεΛܭࢉ͢ΔΑ!!' do context 'komagata͞ΜͷάϨʔυ͸B(ϕʔε100ສԁ)Ͱ' do komagata =

    Person.new(name:'komagata', grade: :B) context 'ධՁ͕༏ल(+50ສԁ)ͷͱ͖' do bonus = Bonus.new(komagata, review: :excellent) check = bonus.call example 'Ϙʔφε͸150ສԁ' do expect(check).to eq(150) context 'machida͞ΜͷάϨʔυ͸A(ϕʔε͕120ສԁ)Ͱ' do machida = Person.new(name:'machida', grade: :A) context 'ධՁ͕;ͭ͏(Մࢉͳ͠)ͷͱ͖' do bonus = Bonus.new(machida, review: :standard) check = bonus.call example 'Ϙʔφε͸120ສԁ' do expect(check).to eq(120) context 'kakutaniͷάϨʔυ͸S(ϕʔε͕160ສԁ)Ͱ' do kakutani = Person.new(name:'kakutani', grade: :S) context 'ධՁ͕࢒೦(2ׂݮ)ͷͱ͖' do bonus = Bonus.new(kakutani, review: :poor) check = bonus.call example 'Ϙʔφε͸128ສԁ' do expect(check).to eq(128) ennnnnd
  4. ❯ rspec -fd fjord_works_spec.rb ϘʔφεΛܭࢉ͢ΔΑ!! komagata͞ΜͷάϨʔυ͸B(ϕʔε100ສԁ)Ͱ ධՁ͕༏ल(+50ສԁ)ͷͱ͖ Ϙʔφε͸150ສԁ machida͞ΜͷάϨʔυ͸A(ϕʔε͕120ສԁ)Ͱ ධՁ͕;ͭ͏(Մࢉͳ͠)ͷͱ͖

    Ϙʔφε͸120ສԁ kakutaniͷάϨʔυ͸S(ϕʔε͕160ສԁ)Ͱ ධՁ͕࢒೦(2ׂݮ)ͷͱ͖ Ϙʔφε͸128ສԁ Finished in 0.00239 seconds (files took 0.2104 seconds to load) 3 examples, 0 failures
  5. class Person attr_reader :name, :grade def initialize(name:, grade:) @name, @grade

    = name, grade end end class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review = person, review end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call case (g = @person.grade) when :S base = 160 apply_review(base) when :A base = 120 apply_review(base) when :B base = 100 apply_review(base) else raise "No such grade: '#{g}'" end end private def apply_review(base) case @review when :excellent base + 50 when :standard base when :poor base * 0.8 else raise "Nu such review: '#{@review}'" end end end
  6. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, review end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call case (g = @person.grade) when :S base = 160 apply_review(base) when :A base = 120 apply_review(base) when :B base = 100 apply_review(base) else raise "No such grade: '#{g}'" end end private def apply_review(base) case @review when :excellent base + 50 when :standard base when :poor base * 0.8 else raise "Nu such review: '#{@review}'" end end end
  7. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, review end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call case (g = @person.grade) when :S base = 160 apply_review(base) when :A base = 120 apply_review(base) when :B base = 100 apply_review(base) else raise "No such grade: '#{g}'" end end private def apply_review(base) case @review when :excellent base + 50 when :standard base when :poor base * 0.8 else raise "Nu such review: '#{@review}'" end end end άϨʔυΛQFSTPOʹਘͶͯ BTL ɺ ج४ֹۚΛ൑ఆ͍ͯ͠Δ ϨϏϡʔͷ൑ఆ಺༰ΛਘͶͯ BTL ɺ ϘʔφεΛ૿ݮ͍ͤͯ͞Δ #POVT͕άϨʔυ΍ϨϏϡʔʹ ฉ͖·Θͬͯ࢓ࣄ͍ͯ͠Δ BTL
  8. Grade = Struct.new(:sym, :base) GRADES = [ Grade.new(:S, 160), Grade.new(:A,

    120), Grade.new(:B, 100) ].each_with_object({}){|g,h| h[g.sym] = g }.freeze class Person attr_reader :name, :grade def initialize(name:, grade:) @name, @grade = name, GRADES[grade] end end class Review class Excellent < Review def call(base) base + 50 end end class Standard < Review def call(base) base end end class Poor < Review def call(base) base * 0.8 end end def self.of(sym) @_types ||= { excellent: Excellent.new, standard: Standard.new, poor: Poor.new } @_types[sym] end def call(base); end end class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review = person, Review.of(review) end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @person.grade.base.then {|b| @review.call(b)} end end QFSTPOͷάϨʔυ͝ͱͷج४ֹۚΛɺ ϨϏϡʔ݁Ռʹ౉ͯ͠ɺϘʔφεΛࢉग़͠ ͍ͯΔ UFMM  #POVT͸άϨʔυͱϨϏϡʔʹ ࢓ࣄΛ͓ئ͍͍ͯ͠Δ UFMM
  9. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, Review.of(review) end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @person.grade.base.then {|b| @review.call(b)} end end QFSTPOͷάϨʔυ͝ͱͷج४ֹۚΛɺ ϨϏϡʔ݁Ռʹ౉ͯ͠ɺϘʔφεΛࢉग़͍ͯ͠Δ UFMM  #POVT͸άϨʔυͱϨϏϡʔʹ ࢓ࣄΛ͓ئ͍͍ͯ͠Δ UFMM
  10. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, Review.of(review) end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @review.call(@person.grade.base) end end ΋ͪΖΜɺ͜ΕͰ΋ߏΘͳ͍  #POVT͸άϨʔυͱϨϏϡʔʹ ࢓ࣄΛ͓ئ͍͍ͯ͠Δ UFMM
  11. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, Review.of(review) end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @person.grade.base.then {|b| @review.call(b)} end end lͦͷਓͷάϨʔυʹɺϨϏϡʔΛద༻ͨ݁͠Ռ͕ ϘʔφεͩΑz #POVT͸άϨʔυͱϨϏϡʔʹ ࢓ࣄΛ͓ئ͍͍ͯ͠Δ UFMM
  12. Grade = Struct.new(:sym, :base) GRADES = [ Grade.new(:S, 160), Grade.new(:A,

    120), Grade.new(:B, 100) ].each_with_object({}){|g,h| h[g.sym] = g }.freeze class Person attr_reader :name, :grade def initialize(name:, grade:) @name, @grade = name, GRADES[grade] end end class Review class Excellent < Review def call(base) base + 50 end end class Standard < Review def call(base) base end end class Poor < Review def call(base) base * 0.8 end end def self.of(sym) @_types ||= { excellent: Excellent.new, standard: Standard.new, poor: Poor.new } @_types[sym] end def call(base); end end #POVT͸άϨʔυͱϨϏϡʔʹ ࢓ࣄΛ͓ئ͍͍ͯ͠Δ UFMM
  13. Grade = Struct.new(:sym, :base) GRADES = [ Grade.new(:S, 160), Grade.new(:A,

    120), Grade.new(:B, 100) ].each_with_object({}){|g,h| h[g.sym] = g }.freeze class Person attr_reader :name, :grade def initialize(name:, grade:) @name, @grade = name, GRADES[grade] end end άϨʔυ͕4ZNCPM͔Βج४ۚ ֹΛ࣋ͬͨ4USVDUʹͳͬͨ
  14. class Review class Excellent < Review def call(base) base +

    50 end end class Standard < Review def call(base) base end end class Poor < Review def call(base) base * 0.8 end end def self.of(sym) @_types ||= { excellent: Excellent.new, standard: Standard.new, poor: Poor.new } @_types[sym] end def call(base); end end class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review = person, Review.of(review) end ϨϏϡʔ͸4ZNCPM͔ΒৼΔ෣ ͍Λ΋ͬͨ3FWJFXΫϥεͷΦ ϒδΣΫτʹͳͬͨ ϘʔφεΛݺͼग़͢ଆ͸ͲͷϨϏϡʔ݁Ռͳͷ͔͸ 4ZNCPMͰࢦఆ͢Δ ΠϯλʔϑΣΠε͸มΘΒͳ͍
  15. … context 'komagata͞ΜͷάϨʔυ͸B(ϕʔε100ສԁ)Ͱ' do komagata = Person.new(name:'komagata', grade: :B) context

    'ධՁ͕༏ल(+50ສԁ)ͷͱ͖' do bonus = Bonus.new(komagata, review: :excellent) check = bonus.call example 'Ϙʔφε͸150ສԁ' do expect(check).to eq(150) … ৼΔ෣͍͸มΘΒͳ͍ͷͰɺςετίʔυ΋มΘΒͳ͍ ʘϦϑΝΫλϦϯάʗ
  16. class Review class Excellent < Review def call(base) base +

    50 end end class Standard < Review def call(base) base end end class Poor < Review def call(base) base * 0.8 end end def self.of(sym) @_types ||= { excellent: Excellent.new, standard: Standard.new, poor: Poor.new } @_types[sym] end def call(base); end end &YDFMMFOU 4UBOEBSE 1PPS ͱճ΋ॻ͍ͯͯɺ෼ྔͷΘΓ ʹ৘ใྔ͕গͳ͍ͷͰ͸  ݸਓͷײ૝Ͱ͢ 
  17. Review = Struct.new(:sym, :apply) REVIEWS = [ Review.new(:excellent, ->(base){ base

    + 50}), Review.new(:standard, ->(base){ base }), Review.new(:poor, ->(base){ base * 0.8 }) ].each_with_object({}){|r,h| h[r.sym] = r }.freeze class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review = person, REVIEWS[review] end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @person.grade.base.then {|b| @review.apply.(b) } end … खଓ͖ΛΦϒδΣΫτʹͨ݁͠Ռɺσʔλ͚ͩʹͳͬͨͷͰ4USVDUͷΠϯελϯεʹͯ͠Έͨɻ ϨϏϡʔ݁Ռͷ໊લ͸ճ͔͠ग़ͯ͜ͳ͍ɻ3VCZ΂ΜΓ 3FWJFXͷ"SSBZΛ3FWJFXͷγϯϘϧΛΩʔʹͨ͠3FWJFXͷ)BTIʹͯ͋͠Δ ͔Β4ZNCPMͰ3FWJFXΛબ΂Δɻ3VCZ΂ΜΓ
  18. ❯ git diff diff --git a/fjord_works.rb b/fjord_works.rb index acb07f1..62f38e1 100644

    --- a/fjord_works.rb +++ b/fjord_works.rb @@ -6,11 +6,13 @@ GRADES = [ ].each_with_object({}){|g,h| h[g.sym] = g }.freeze class Person - attr_reader :name, :grade + attr_reader :name def initialize(name:, grade:) @name, @grade = name, GRADES[grade] end + + def base_salary; @grade.base end end Review = Struct.new(:sym, :apply) @@ -28,6 +30,6 @@ class Bonus # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call - @person.grade.base.then {|b| @review.apply(b)} + @person.base_salary.then {|b| @review.apply.(b)} end end
  19. Review = Struct.new(:sym, :apply) REVIEWS = [ Review.new(:excellent, ->(base){ base

    + 50}), Review.new(:standard, ->(base){ base }), Review.new(:poor, ->(base){ base * 0.8 }) ].each_with_object({}){|r,h| h[r.sym] = r }.freeze class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review = person, REVIEWS[review] end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call @person.base_salary.then {|b| @review.apply.(b) } end … ਓؒͷج४ֹۚʹϨϏϡʔ݁ՌΛద༻ͨ͠ͷ͕Ϙʔφε
  20. class Bonus attr_reader :person, :review def initialize(person, review:) @person, @review

    = person, review end # Ϙʔφε: άϨʔυ͝ͱͷϕʔεֹۚΛධՁʹΑͬͯ૿ݮֹͤͨۚ͞ def call case (g = @person.grade) when :S base = 160 apply_review(base) when :A base = 120 apply_review(base) when :B base = 100 apply_review(base) else raise "No such grade: '#{g}'" end end private def apply_review(base) case @review when :excellent base + 50 when :standard base when :poor base * 0.8 else raise "Nu such review: '#{@review}'" end end end #POVT͕άϨʔυ΍ϨϏϡʔʹ ฉ͖·Θͬͯ࢓ࣄ͍ͯ͠Δ BTL
  21. w͍·ͷؾ࣋ͪ ײ৘  ͋ͳ͕ͨॻ͔ͳ͚Ε͹୭ʹ΋఻ΘΒͳ͍ɻl૬खʹ఻ΘΔΑ͏ʹzςΩετͰॻ͘ʹ͸܇࿅͕ඞཁͩɻ w΍ͬͨ͜ͱ ࣄ࣮  ࠓ೔΋Ұ೔͕Μ͹ͬͨৄ͘͠ॻ͖͍ͨͩΖ͏͚ͲɺΈΜͳ͸ৄࡉΛಡΈ͍͔ͨͳ  wΘ͔ͬͨ͜ͱ

    ҙݟ ղऍ  ΋ͪΖΜɺײ৘Ҏ֎΋ద੾ʹ఻ΘΔΑ͏ʹςΩετग़ྗ͢Δʹ͸܇࿅ɺ܇࿅ɺ܇࿅ɻ w࣍ʹ΍Δ͜ͱ ܭը ද໌  ߟ͑Δ͜ͱ͸େࣄ͚ͩΕͲɺ໌೔ͷࣗ෼΁ͷஔ͖खࢴ ໌೔ͷࣗ෼ʹద੾ʹ఻ΘΔΑ͏ʹॻ͚Δ͔ͳ  wγϟ΢τΞ΢τ ײँ  νʔϜʹײँɻ஥ؒʹײँɻΑ͍ৼΔ෣͍ɺॿ͔ͬͨ͜ͱΛϑΟʔυόοΫͯ͠૿͑ͨΒ͏Ε͘͠ͳ͍ l೔ใz͸Ͳ͜ʹྗΛೖΕͯॻ͘ͷ͕Α͍͔
  22. w͍·ͷؾ࣋ͪ ײ৘  ͋ͳ͕ͨॻ͔ͳ͚Ε͹୭ʹ΋఻ΘΒͳ͍ɻl૬खʹ఻ΘΔΑ͏ʹzςΩετͰॻ͘ʹ͸܇࿅͕ඞཁͩɻ w΍ͬͨ͜ͱ ࣄ࣮  ࠓ೔΋Ұ೔͕Μ͹ͬͨৄ͘͠ॻ͖͍ͨͩΖ͏͚ͲɺΈΜͳ͸ৄࡉΛಡΈ͍͔ͨͳ  wΘ͔ͬͨ͜ͱ

    ҙݟ ղऍ  ΋ͪΖΜɺײ৘Ҏ֎΋ద੾ʹ఻ΘΔΑ͏ʹςΩετग़ྗ͢Δʹ͸܇࿅ɺ܇࿅ɺ܇࿅ɻ w࣍ʹ΍Δ͜ͱ ܭը ද໌  ߟ͑Δ͜ͱ͸େࣄ͚ͩΕͲɺ໌೔ͷࣗ෼΁ͷஔ͖खࢴ ໌೔ͷࣗ෼ʹద੾ʹ఻ΘΔΑ͏ʹॻ͚Δ͔ͳ  wγϟ΢τΞ΢τ ײँ  νʔϜʹײँɻ஥ؒʹײँɻΑ͍ৼΔ෣͍ɺॿ͔ͬͨ͜ͱΛϑΟʔυόοΫͯ͠૿͑ͨΒ͏Ε͘͠ͳ͍ l೔ใz͸Ͳ͜ʹྗΛೖΕͯॻ͘ͷ͕Α͍͔