Slide 1

Slide 1 text

ͳͥRubyʹ͸BooleanΫϥε ͕ͳ͍ͷ͔ BuriKaigi 2024 OKURA Masafumi, 2024-01-20

Slide 2

Slide 2 text

BuriKaigi

Slide 3

Slide 3 text

3ճ໨ͷొஃ 2020, 2022, 2024

Slide 4

Slide 4 text

ࠓճͷ ݸਓత ϨΪϡϨʔγϣϯ

Slide 5

Slide 5 text

Ჳʹؔ܎ͷ͋Δ τʔΫ

Slide 6

Slide 6 text

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

ϒϦ

Slide 9

Slide 9 text

ϒʔϦ

Slide 10

Slide 10 text

ϒʔϦΞϯ

Slide 11

Slide 11 text

Boolean!

Slide 12

Slide 12 text

Rubyʹ͸ BooleanΫϥε͕ ͳ͍ʂ

Slide 13

Slide 13 text

ϒʔϦΞϯɿͳͥRubyʹ͸ BooleanΫϥε͕ͳ͍ͷ͔ BuriKaigi 2024 OKURA Masafumi, 2024-01-20

Slide 14

Slide 14 text

ࣗݾ঺հ

Slide 15

Slide 15 text

ࣗݾ঺հ • ໊લɿେ૔խ࢙ • ॴଐɿϑϦʔϥϯε • ՝֎׆ಈɿKaigi on RailsνʔϑΦʔΨφΠβʔɺOSS։ൃɺ֤छొஃ ʢEuruko, RubyConfTw, VimConf, σϒαϛ2024ʣ • ޷͖ͳݴޠͳͲɿRubyɺRailsɺNeovim • ෋ࢁྺɿ2ճ໨

Slide 16

Slide 16 text

ʲະঝ୚޿ࠂཝʳ ʲ͓࢓ࣄืूʳ ʲৄࡉ͸࠙਌ձʳ

Slide 17

Slide 17 text

͓඼ॻ͖

Slide 18

Slide 18 text

ࠓ೔ͷ͓࿩ 1. Fact: Rubyʹ͓͚ΔBooleanͷѻ͍ʹ͍ͭͯ 2. Opinion: RubyʹBooleanΫϥε͕ͳͯ͘΋Α͍ཧ༝ʹ͍ͭͯ

Slide 19

Slide 19 text

͋Εɺܕͷ࿩͸ʁ

Slide 20

Slide 20 text

20෼ʹऩ·Βͳ ͔ͬͨͷͰׂѪ

Slide 21

Slide 21 text

ࠓճͷτʔΫͷ ࣋ͪؼΓ ʢTakeawayʣ

Slide 22

Slide 22 text

ࠓճͷτʔΫͰ࣋ͪؼͬͯ΄͍͜͠ͱ • Ruby͕ਅِ஋ؚΉΦϒδΣΫτʹରͯ͠औ͍ͬͯΔΞϓϩʔν • ʮϓϦϛςΟϒʯ͕ଘࡏ͠ͳ͍ͱ͍͏͜ͱ • ϓϩάϥϛϯάݴޠʹ͓͚ΔҙࢥܾఆͷҰྫ • BooleanΛ௥Ճ͠ͳ͍ͱ͍͏ܾఆ • ʮσβΠϯࢥߟʯ

Slide 23

Slide 23 text

1. Rubyʹ͓͚Δ Booleanͷѻ͍

Slide 24

Slide 24 text

Seeing Is Believing

Slide 25

Slide 25 text

Rubyʹ͓͚ΔBooleanͷѻ͍ • TrueClassͱFalseClass͕ͦΕͧΕtrueͱfalseͷΫϥε • ͜ΕΒΫϥε͸newϝιουΛݺ΂ͳ͍ʢγϯάϧτϯʣ • TrueClassͱFalseClassʹ͸ڞ௨ͷ਌ΫϥεͳͲ͸ͳ͍ • to_boolͷΑ͏ͳϝιου͸ଘࡏ͠ͳ͍ʢ!!Ͱ୅༻Մೳʣ • Ifจʹ͸ͲͷΑ͏ͳΦϒδΣΫτͰ΋࢖͑ΔʢfalseͱnilҎ֎શͯtrueʣ

Slide 26

Slide 26 text

ଞͷݴޠͰ͸ɺ true/false͸ଈ஋ ͔΋͠Εͳ͍

Slide 27

Slide 27 text

Ұํɺ Rubyʹ͸ ଈ஋͕ͳ͍

Slide 28

Slide 28 text

શͯ͸ ΦϒδΣΫτ

Slide 29

Slide 29 text

શͯͷ ΦϒδΣΫτʹ Ϋϥε͕͋Δ

Slide 30

Slide 30 text

ଐ͍ͯ͠Δ Πϯελϯε͕ 1͔ͭ͠ͳ͍Ϋϥε

Slide 31

Slide 31 text

TrueClass FalseClass NilClass

Slide 32

Slide 32 text

ศ্ٓଘࡏͯ͠ ͍Δͱ΋ݴ͑Δ

Slide 33

Slide 33 text

·ͣॻ͔ͳ͍

Slide 34

Slide 34 text

v.is_a?(TrueClass)

Slide 35

Slide 35 text

v == true

Slide 36

Slide 36 text

2. Rubyʹ BooleanΫϥε͕ ͳͯ͘΋Α͍ཧ༝

Slide 37

Slide 37 text

https://bugs.ruby- lang.org/issues/ 12515

Slide 38

Slide 38 text

Create "Boolean" superclass of TrueClass / FalseClass

Slide 39

Slide 39 text

ɹɹɹɹɹɹɹ٫Լ Status: Rejected

Slide 40

Slide 40 text

Rejected for several reasons: many gems and libraries had already introduced Boolean class. I don't want to break them. true and false are the only representative of true-false values. In Ruby. nil and false are falsy values, and everything else is a true value. There's no meaning for having a superclass of TrueClass and FalseClass as Boolean. Matz. ʢԼઢ͸Ҿ༻ऀʣ

Slide 41

Slide 41 text

Rubyʹ͓͍ͯ͸ trueͱfalse͸ ਅِ஋ͷ୅ද

Slide 42

Slide 42 text

ਅͷ୅දɿtrue ِͷ୅දɿfalse

Slide 43

Slide 43 text

ͦΕҎ֎ͷɺ ਅͷྫɿ42, [], … ِͷྫɿnil

Slide 44

Slide 44 text

trueͱfalse͸ 1Ϗοτͷ৘ใྔ

Slide 45

Slide 45 text

trueͱfalse͸ Կ΋ڞ༗ ͍ͯ͠ͳ͍

Slide 46

Slide 46 text

trueͱfalse͕ ಉ͡Ϋϥεʹ ଐ͢Δͱ͸ʁ

Slide 47

Slide 47 text

Ϋϥεͱ͸ʁ

Slide 48

Slide 48 text

ڞ௨͢Δ΋ͷ͕ ·ͱ·͍ͬͯΔ

Slide 49

Slide 49 text

ଐ͍ͯ͠Δ Πϯελϯε͕ ଐੑΛڞ༗͠ͳ͍ʁ

Slide 50

Slide 50 text

BooleanΫϥεʹ ϝιου͕ଘࡏ ͠ͳ͍ʁ

Slide 51

Slide 51 text

Rejected for several reasons: many gems and libraries had already introduced Boolean class. I don't want to break them. true and false are the only representative of true-false values. In Ruby. nil and false are falsy values, and everything else is a true value. There's no meaning for having a superclass of TrueClass and FalseClass as Boolean. Matz. ʢԼઢ͸Ҿ༻ऀʣ

Slide 52

Slide 52 text

ڞ௨ͷ਌Ϋϥε ʹ͸ҙຯ͕ͳ͍

Slide 53

Slide 53 text

Ͱ΋Boolean͕ ͋ͬͨ΄͏͕ ศརͳͷͰ͸ʁ

Slide 54

Slide 54 text

https://bugs.ruby- lang.org/issues/ 12515

Slide 55

Slide 55 text

Ϣʔεέʔε

Slide 56

Slide 56 text

v.is_a?(Boolean)

Slide 57

Slide 57 text

ಉ͡ػೳɿ v == true || v == false

Slide 58

Slide 58 text

΄΅͜Ε͚ͩ

Slide 59

Slide 59 text

Rejected for several reasons: many gems and libraries had already introduced Boolean class. I don't want to break them. true and false are the only representative of true-false values. In Ruby. nil and false are falsy values, and everything else is a true value. There's no meaning for having a superclass of TrueClass and FalseClass as Boolean. Matz. ʢԼઢ͸Ҿ༻ऀʣ

Slide 60

Slide 60 text

Θ͟Θ͟ޓ׵ੑΛ ؾʹͯ͠·Ͱ௥Ճ ͠ͳͯ͘Α͍

Slide 61

Slide 61 text

RubyʹBoolean Ϋϥε͕ͳͯ͘΋ Α͍ཧ༝·ͱΊ

Slide 62

Slide 62 text

RubyʹBooleanΫϥε͕ͳͯ͘΋Α͍ཧ༝ • trueͱfalse͕ڞ༗͢Δ΋ͷ͕Կ΋ͳ͍ • ڞ௨ͷ਌ΫϥεΛ࣋ͭ͜ͱʹҙຯ͕ͳ͍ • Ϣʔεέʔε͕গͳ͍ • ͦ͏·Ͱͯ͠࡞Δ΄ͲͰ͸ͳ͍ • ྺ࢙తཧ༝΋͋Γͦ͏ • طଘͷBooleanΫϥεΛഁյͯ͠͠·͏

Slide 63

Slide 63 text

ࠓճͷൃදͰ ࢲֶ͕Μͩ͜ͱ

Slide 64

Slide 64 text

ࠓճͷֶͼ • ҰͭͷissueΛਂ۷Δͱ৭ʑͳҙݟ͕ަΘ͞Ε͍ͯͯ໘ന͍ • ʮࣗવʯʮศརʯ͸ܾఆతͳཧ༝ʹͳΒͳ͍ͱ͖͕͋Δ • ࣮͸ଞͷݴޠʹ͸͍͍ͩͨBoolean͕͋Δ • ϓϩάϥϛϯάݴޠͷઃܭͰࣗ໌ͳ͜ͱ͸গͳ͍ʢͱࢥͬͨʣ

Slide 65

Slide 65 text

Thank you!