= 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
= 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
= 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
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
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
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ʹͳͬͨ
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Ͱࢦఆ͢Δ ΠϯλʔϑΣΠεมΘΒͳ͍
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 ͱճॻ͍ͯͯɺྔͷΘΓ ʹใྔ͕গͳ͍ͷͰ ݸਓͷײͰ͢
= 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