Slide 1

Slide 1 text

8IBUT$PPLJOH*O 3VCZ ෢ऀথل !LOV

Slide 2

Slide 2 text

ࣗݾ঺հ w ෢ऀথل"LJOPSJ.VTIB w 5XJUUFSIUUQTUXJUUFSDPNLOV w (JU)VCIUUQTHJUIVCDPNLOV w גࣜձࣾϚνϚν w 3VCZίϛολʔ w 'SFF#4%ίϛολʔ w 5FBN/PLPHJSJ w )VHJOOڞಉ։ൃऀ

Slide 3

Slide 3 text

ࣗݾ঺հ w ࢓ࣄʢൈਮʣ w γʔαʔϒϩά͓Αͼ0&.αʔϏε w ΠʔϓϥεެࣜΞϓϦͷόοΫΤϯυ w ૬੮԰ެࣜΞϓϦͷόοΫΤϯυ w ۙ͝ॴ4/4ϚνϚν

Slide 4

Slide 4 text

ϚνϚν w גࣜձࣾϚνϚν w ໨ࠇ۠ɺֶܳେֶӺ͔Βెา෼ w ձࣾ঺հIUUQCJUMZNBDIJNBDIJJOUSP w ʮͻΒ͔Εͨɺͭͳ͕Γͷ͋Δ஍ҬࣾձΛͭ͘Δʯ w ۙ͝ॴ4/4ˍ஍Ҭ৘ใϝσΟΞIUUQTNBDIJNBDIJDPN w ΤϯδχΞ࠾༻தʂIUUQTXXXXBOUFEMZDPNDPNQBOJFTNBDIJNBDIJJODQSPKFDUT w ϚνϚνΛࢧ͑Δٕज़$IUUQTUDP0.FIZ-:& 3BJMT 3FBDU 1PTUHSF42- ʜ w ٕज़ϒϩάIUUQTUFDINBDIJNBDIJDPN

Slide 5

Slide 5 text

3VCZͰͷ։ൃ׆ಈ w ϨϙδτϦ؅ཧऀ w ։ൃΠϯϑϥ੔උ w ඪ४ϥΠϒϥϦͷॆ࣮ w %JHFTUͷ֦ுɺϋογϡΞϧΰϦζϜ௥Ճ w 4FUͷ࣮૷ w CJHEFDJNBM TZTMPH JQBEES [MJCͳͲͷΠϯϙʔτࢧԉ΍อक w 4IFMMXPSETʹTIFMMFTDBQF TIFMMKPJOΛ࣮૷ w 3VCZͷϦϦʔε

Slide 6

Slide 6 text

3VCZͰͷ։ൃ׆ಈ w ૊ࠐΫϥεͷ֦ு w "SSBZTMJDF w &OVNFSBUPSͷಋೖ &OVNFSBCMFͷ֦ு w FBDI@DPOT FBDI@TMJDF w FBDI@XJUI@PCKFDU

Slide 7

Slide 7 text

3VCZͰͷ։ൃ׆ಈ w ࠷ۙ͸ɺ݄࣍ͷ3VCZ։ൃऀձٞʹग़੮ͯ͠ɺओʹ3BJMT 8FC։ൃऀͷ؍఺͔ΒΠϯϓοτͨ͠Γɺࣗ෼͕୲౰͢ ΔϥΠϒϥϦΛ͍͡Δ׆ಈ͕ϝΠϯͰ͢ɻ

Slide 8

Slide 8 text

3VCZʹ޲͚ͯ w ·͕ͩग़͔ͯΒϲ݄͔͠ܦ͍ͬͯ·ͤΜ͕ɺ΍ʹ޲͚ͨػೳ։ൃ΍ٞ ࿦͸͍Ζ͍Ζਐߦ͍ͯ͠·͢ɻͦͷҰ୺Ͱ΋ɺָ͘͠͝঺հͰ͖ͨΒͱࢥ͍·͢ɻ w ͜͜Ͱ͝঺հ͢Δͷ͸͋͘·ͰዞҙతʹબΜͩྫʹա͗ͣɺ໢ཏੑ͸͋Γ·ͤΜɻ w ڵຯͷ͋Δํ͸/&84ϑΝΠϧɺ3VCZ։ൃऀձٞͷٞࣄ࿥ɺ3FENJOFͰͷν έοτϕʔεͷٞ࿦Λ௥͍͔͚·͠ΐ͏ɻ w ։ൃऀಉ࢜ͷٞ࿦͸ඇৗʹଟ૬తͰߴจ຺Ͱ͕͢ɺʮ͍ΖΜͳ͜ͱ͕͋ΔΜͩͳ͋ʯ ఔ౓ͷड͚औΓͰߏ͍·ͤΜɻ w ։ൃਞ΁ͷϑΟʔυόοΫ͸ɺ͍ΖΜͳνϟϯωϧΛ௨ͯ͡ؾܰʹͲ͏ͧʂ5XJUUFS ͰͭͿ΍͚ͩ͘Ͱ΋໨ʹೖΔ͔΋

Slide 9

Slide 9 text

͓͠ͳ͕͖ w ೖͬͨ΋ͷ w ৽จ๏obj.:meth w ແϒϩοΫQSPDͷஈ֊తഇࢭ w &OVNFSBCMFUBMMZ w ٫Լ͞Εͨ΋ͷ w ։ൃதɾݕ౼தͷػೳ w ࠓޙͷ3VCZͷ༧ఆ

Slide 10

Slide 10 text

obj.:meth w obj.method(:meth)ͷ୹ॖจ๏ w ϝιουΦϒδΣΫτΛऔΓग़͢ w ैདྷͷ0CKFDUNFUIPE͸ϝιουݺͼग़ͩͬͨ͠ w ϝιουΛऔΔͨΊʹϝιουΛݺͿඞཁ͕͋Δʜ
 ͍͔ʹ΋3VCZΒ͍͚͠Ͳʜ w ΦʔόʔϥΠυ͞Ε͍ͯΔ͔΋͠Εͳ͍
 ʢྫ3FRVFTUΦϒδΣΫτ)551ϝιουΛฦ͢ʣ w 0CKFDUͰͳ͘#BTJD0CKFDUΛܧঝͨ͠ΦϒδΣΫτʹ͸NFUIPEϝιο υ͕ͳ͍

Slide 11

Slide 11 text

obj.:meth w ೚ҙͷΦϒδΣΫτʹରͯ͠ϝιουΛऔΓग़͍ͨ͠ͱ͖͸ɺΫϥε ͔ΒϝιουΛऔΓग़ͯ͠CJOEDBMM͢Δͱ͍͏ᷖԕͳखஈΛऔΔ ඞཁ͕͋ͬͨ • Object.instance_method(:method)
 .bind(obj)
 .call • ΦϒδΣΫτͷૉੑΛ໰ΘͣɺϝιουΛऔΓग़͢୹͍ه๏͕΄͍͠ • ͍͔ͭ͘Ҋ͕͕͋ͬͨɺطଘจ๏ͱͷিಥ͕ͳ͘ɺγϯϘϧه๏ ͔ΒϝιουΛ࿈૝͠΍͍͢ʮobj.:methʯʹܾఆ

Slide 12

Slide 12 text

obj.:meth w ͨͱ͑͹ɺ͜͏͍͏ίʔυ͕୹͘ॻ͚ΔΑ͏ʹ w lines.map { |line| JSON.parse(line) }
 ↓
 lines.map(&JSON.:parse) • ͨͩ͠ɺself͸লུͰ͖ͳ͍͜ͱͱͨ͠ w lines.each { |line| puts line }
 ↓
 lines.each(&self.:puts) w obj.each(&.:meth)Λڐͯ͠͠·͏ͱɺobj.each(&:meth)ͱݟͨ໨͕ ӝೋͭͳͷʹશવҧ͏ҙຯʹͳΔͷͰ໨ʹ༏͘͠ͳ͍ɺͱ͍͏.BU[ͷࢦఠʹ ΑΔ

Slide 13

Slide 13 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w ϝιουఆٛதͰϒϩοΫͳ͠ͷQSPDʹΑͬͯϝιουʹ౉͖ͬͯͨϒϩοΫΛ औಘ͢Δ͜ͱ͕Ͱ͖Δ • def each_key
 keys.each(&proc)
 end • proc͸Proc.newͱॻ͍ͯ΋ಉ͡ɺଞʹlambda΋͋Δ • block_given?ͰϒϩοΫ͕౉͞Ε͔ͨͲ͏͔Λ൑ఆͰ͖ɺyieldͰݺͼग़ͤ Δͷͱ߹Θͤͯɺ໌ࣔతʹҾ਺Λॻ͔ͳͯ͘΋౉͞ΕͨϒϩοΫΛར༻Ͱ͖ͨ w ͜ͷػೳΛഇࢭ͠Α͏ͱ͍͏ํ޲ʹͳͬͨ w ແϒϩοΫprocͱProc.new͸͔ΒܯࠂɺແϒϩοΫlambda͸ഇࢭ

Slide 14

Slide 14 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w എܠͱͯ͠͸ɺ࠷దԽ΍ޡΓݕग़ͷͨΊɺ͋Δϝιου͕ ϒϩοΫΛऔΔͷ͔Ͳ͏͔Λ੩తʹ൑ఆ͍ͨ͠ɺཧ૝తʹ ͸Ҿ਺ϦετͰ໌͍ࣔͤͨ͞ɺͱ͍͏ಈػ͕͋Δ w ϒϩοΫΛऔΒͳ͍ϝιουʹϒϩοΫΛ౉ͯ͠΋ɺϝ ιουଆͰνΣοΫ͠ͳ͍ݶΓΤϥʔ΍ܯࠂʹ͸ͳΒ ͳ͍ w ࢖ΘΕΔͱࢥͬͯϒϩοΫΛ౉͕࣮ͨ͠͸࢖ΘΕͣແ ҙຯͱ͍͏ޡΓʹؾ͚ͮͳ͍ɺͱ͍͏໰୊

Slide 15

Slide 15 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w ͨͩɺ$3VCZʹ͸௕͍ؒɺdef method(&block)ͱϒϩοΫΛҾ਺Ͱ ड͚औΔͷ͸஗͍ͱ͍͏໰୊͕͋Γɺख़࿅޻͸ॻ͍ͯ͘Εͳ͔ͬͨ w yield͸ɺ౉͞ΕͨϒϩοΫΛ௚઀ݺͿ໋ྩʹίϯύΠϧ͞ΕΔ w ҰํɺԾҾ਺Ϧετʹ&blockͱॻ͘ͱɺϒϩοΫ͔Β1SPDΦϒδΣΫ τΛੜ੒্ͨ͠ͰɺϩʔΧϧม਺ʹ୅ೖ͞ΕΔ w ͞Βʹblock.callͱ͢ΔͱϩʔΧϧม਺Λࢀর͠ɺ1SPDΦϒδΣΫ τʹରͯ͠ϝιου͕ݺͼग़͞ΕΔ w Կεςοϓ΋ଟ͍ʜ

Slide 16

Slide 16 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w 3VCZͰɺԾҾ਺Ϧετʹ&blockͱॻ͍ͯ΋ɺ࣮ࡍʹblockΛ࢖͏ ·Ͱ1SPDΦϒδΣΫτͷੜ੒Λ஗Ԇ͢ΔΑ͏ʹͳͬͨ w தͰblock_given?ͱyieldΛ࢖ͬͨ··ɺϒϩοΫΛऔΔ͜ͱΛԾ Ҿ਺ϦετͰදݱͯ͠΋ੑೳ্ͷϖφϧςΟ͕ͳ͘ͳͬͨ w 3VCZͰɺblock.call͸yieldͱಉ౳ͷੑೳʹͳͬͨ w ͨͩɺcallͷΦʔόʔϥΠυ༗ແΛ֬ೝ͢ΔͳͲ໘౗ͳ࣮૷ͷࣀ෺ w ͜ΕͰɺ໌ࣔతʹ&blockͱblock.callΛ࢖͏ελΠϧΛਪ঑Ͱ͖ΔΑ ͏ʹͳͬͨ

Slide 17

Slide 17 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w ٯʹɺʮϒϩοΫΛऔΒͳ͍͜ͱʯΛ໌ࣔͰ͖ΔΑ͏ʹ͢΂͖͔ɺͱ͍ ͏ٞ࿦΋ਐΜͰ͍Δ w ౰ॳ͸ɺdef foo(&nil)ͱॻ͘͜ͱʹ͢Ε͹͍͍ͷͰ͸ɺͱ·ͱ ·Γ͔͚ͨ w ͔͠͠ɺͦ͏͢ΔͱʮϒϩοΫΛऔΒͳ͍ϝιου͢΂ͯʹ&nilΛ ೖΕΑ͏ʯͱ͍͏େྔͷ13͕Ұؾʹԡ͠دͤΔةዧ͕͋ΔͷͰऔ Γ΍Ίʹ w ݱࡏ͸ɺίϯύΠϧ࣌ͷ੩తղੳͰͰ͖ͳ͍͔ɺͱ͍͏औΓ૊Έ͕ࢼ͞ Ε͍ͯΔ

Slide 18

Slide 18 text

ແϒϩοΫQSPDͷஈ֊తഇࢭ w ͨͩɺTVQFSͱ͍͏น͕ൃݟ͞ΕΔ w super͋Δ͍͸super()ͱॻ͘ͱɺԿ΋ࢦఆ͍ͯ͠ͳ͍͕ɺ ౉͖ͬͯͨϒϩοΫΛεʔύʔϝιουʹ౉͢Α͏ʹͳ͍ͬͯΔ w superͷํ͸෼͔Δ͕ɺsuper()ͷํ͸Ұମͳͥʜ w ͦͷͨΊɺεʔύʔϝιου΋ḷͬͯݟͳ͍ͱϒϩοΫҾ਺Λ࢖ͬ ͍ͯΔͷ͔͸Θ͔Βͳ͍ w ݱࡏ΋طଘͷϢʔβίʔυΛؚΊௐࠪɾݚڀ͕ਐߦத$

Slide 19

Slide 19 text

&OVNFSBCMFUBMMZ w ཁૉΛ஋ผʹ਺͑Δϝιου • ["a", "b", "b", "c", "a", "a"].tally
 # => { "a" => 3, "b" => 2, "c" => 1 } • SQLͷGROUP BY+COUNT()ͷΑ͏ͳ΋ͷ • ࠓ·Ͱ͸group_byΛ࢖ͬͯ͜Μͳ෩ʹͤ͟ΔΛಘͳ͔ͬͨॲཧ • ["a", "b", "b", "c", "a", "a"]
 .group_by(&:itself)
 .transform_values(&:size)

Slide 20

Slide 20 text

&OVNFSBCMFUBMMZ w ౰ॳ͸count_byͱ͍͏໊લͰɺϒϩοΫΛऔΔܗͰఏҊ͞Ε͍ͯͨʢϒϩοΫΛద ༻ͨ͠஋Ͱूܭ͢Δʣ w ͔͠͠ɺ͍͔ͭ͘ͷ೉఺ͰࢍಉΛಘΒΕͣ w ໊લ͕͍·͍ͪcountͱͷରশੑ͕ͳ͍ʢsort_bysort max_bymaxͳ Ͳ͔Βͷྨਪ͕ޮ͔ͳ͍ʣ w ػೳ͕ଟ͍ϒϩοΫΛऔΔͷ͸ΦϓγϣφϧͰ͸ʁඞཁͳΒmap͔ͯ͠Β౉ ͤ͹͍͍ w γϡϫϧπม׵͍ͨ͜͠ͱ΋͋Δ͔΋͠Εͳ͍͕ɺ୅ද஋ΛͲ͏͢Δ͔࢓ ༷ΛܾΊ೉͍ w tallyͱ͍͏໊લΛಘͯɺϒϩοΫΛऔΒͳ͍γϯϓϧͳܗͰ࠾༻

Slide 21

Slide 21 text

&OVNFSBCMFUBMMZ w UBMMZͱ͸਺Λ਺͑ͯه࿥͢Δ͜ͱͰɺࢴ΍ࠇ൘ʹҰຊͣͭઢΛॻ ͖ͳ͕ΒΧ΢ϯτ͢ΔͨΊͷه߸ͷݺশͰ΋͋Δʢ೔ຊͰͷʮਖ਼ʯ ʹ͋ͨΔه߸ɺʮ㠟ʯͷΑ͏ͳܗʣ w ͪͳΈʹ6OJDPEFͰʮਖ਼ʯͱͱ΋ʹೖΓ·ͨ͠
 IUUQTUXJUUFSDPNLFO@MVOEFTUBUVT

Slide 22

Slide 22 text

٫Լ͞Εͨ΋ͷ w BVUPMPBEͷഇࢭ⚡ w .BU[͸εϨουηʔϑςΟͷ؍఺͔Βຊ࣭తʹةͳ͍ͷͰͣͬͱফͨ͠ ͍೿ w 3BJMT͕DPOTU@NJTTJOHͰͷࣗಈϩʔυػߏΛ΍ΊͯBVUPMPBEΛ࢖͏ ;FJUXFSLΛͰ࠾༻ɺͱ͍͏͜ͷλΠϛϯάͰ͸͠͝Λ֎͢ͷ͔⽐ͱ ࢲͷதͰ૽વ w ͔͠͠3BJMTΞϓϦͷ։ൃͰ͸FBHFSMPBEJOHͩͱϓϩηεىಈɾ࠶ىಈ ͕ॏ͗͢ΔͷͰ͜͏͍͏ػߏ͸ඞਢͱઆಘ☝ w গͳ͘ͱ΋3VCZYͷؒ͸࢒͢ɺͱ͍͏.BU[ͷݴ࣭Λಘͨ

Slide 23

Slide 23 text

٫Լ͞Εͨ΋ͷ w BVUPMPBEͷഇࢭ w ͦͷޙɺBVUPMPBEΛΑΓ҆શʹ͢ΔͨΊͷݚڀͱվम͕ਐΜͰ ͍Δ w IUUQXXXBLSPSHEIUNMB@@ w IUUQXXXBLSPSHEIUNMB@@@ w IUUQTCVHTSVCZMBOHPSHJTTVFT w IUUQTCVHTSVCZMBOHPSHJTTVFT

Slide 24

Slide 24 text

٫Լ͞Εͨ΋ͷ w "SSBZ΍)BTI΋ɺ4USJOHͷΑ͏ʹσϑΥϧτͰϑϦʔζ͢ΔϞʔυ͕΄͠ ͍ɺ͋Δ͍͸୯߲ͰEVQGSFF[F͍ͨ͠ w IUUQTCVHTSVCZMBOHPSHJTTVFT w ʮͦΜͳʹ΄͍͠ʁʯ·ͩջٙత w Ͱ΋3VCPDPQར༻ऀ͔Β͢Δͱɺఆ਺഑ྻɾϋογϡʹ.freezeΛ෇ ͚ͯճΒΕΔܦݧ͸ۤʑ͍͠ʜ w ͍ͣΕ·ͨνϟϯε͋Δ͔΋

Slide 25

Slide 25 text

։ൃதɾݕ౼தͷػೳ w #FHJOMFTT 4UBSUMFTT 3BOHFT w IUUQTCVHTSVCZMBOHPSHJTTVFT w &OEMFTT3BOHFT @ary[1..] ͕ೖͬͨͷͰɺࠓ౓͸ࠨ୺ଆΛলུͨ͠΋ͷ΋ ೖΕ͍ͨ w "DUJWF3FDPSEͳͲͷ%4-ͰศརProduct.where(price: ..1000) w &OEMFTT3BOHFT΋ಋೖޙʹ͍͔ͭ͘໰୊͕ൃݟɾରॲ͞ΕͨͷͰɺͦΕΒͷ ख౰͕ͯऴΘͬͯམͪண͍͔ͯΒ w &OVNFSBUPS:JFMEFSUP@QSPD w IUUQTCVHTSVCZMBOHPSHJTTVFT

Slide 26

Slide 26 text

։ൃதɾݕ౼தͷػೳ w σϑΥϧτϒϩοΫҾ਺@1 @2 ʜ w IUUQTCVHTSVCZMBOHPSHJTTVFT w ͣͬͱ๬·Ε͍ͯΔػೳnumbers.map { "%02x" % @1 } w طଘจ๏ͱিಥͷͳ͍ح੻ͷҊʢ@1 @2,…ʣʹظ଴ w ύλʔϯϚονػೳʢDBTFJOߏจʣ w IUUQTCVHTSVCZMBOHPSHJTTVFT w ڧ͘଴ͪ๬·Ε͖ͯͨػೳ w εΫϦϓτݴޠͷதͰ͸ڧྗͰ3VCZͷڧΈͱݴΘΕ͖͕ͯͨɺؔ਺ܕݴޠ͕ϝδϟʔ ʹͳ͖ͬͯͨࠓͰ͸ͪΐͬͱݟྼΓ͢Δ

Slide 27

Slide 27 text

։ൃதɾݕ౼தͷػೳ w &4ελΠϧͷϋογϡ؆ศه๏ʢpFMEQVOOJOHʣ w IUUQTCVHTSVCZMBOHPSHJTTVFT w {
 name: name,
 type: type,
 created_at: created_at
 }
 ↓
 { name, type, created_at }
 
 ͳͲͱॻ͖͍ͨͳɺͱ͍͏ྫͷ΍ͭ w .+*5ʹΑΔ͞ΒͳΔߴ଎Խ

Slide 28

Slide 28 text

ࠓޙͷ3VCZͷ༧ఆ w ೥݄ w ೔ʹ։ൃऀձٞIUUQTCVHTSVCZMBOHPSHJTTVFT w 6OJDPEF͕ग़ͨΒɺ3VCZYΛϦϦʔε w ೥݄ w 3VCZ,BJHJձظલ೔ʹ։ൃऀձٞ w ৽ݩ߸͕ൃද͞ΕͨΒ6OJDPEF͕ग़Δ w ͦΕΛ଴ͬͯ3VCZZΛϦϦʔε w ຖ݄։ൃऀձٞ w νϟϯε͸ຖ݄ IUUQTCVHTSVCZMBOHPSHJTTVFT w ೥݄ w ೔3VCZϦϦʔε