Slide 1

Slide 1 text

Ruby cologne.rb Nein! Doch! Ohh

Slide 2

Slide 2 text

Previously on Ruby is Magic (viele) Absurditäten und (etwas) Nützliches Verrückter Syntax Inkonsistenzen Kuriositäten

Slide 3

Slide 3 text

Einflüsse auf Ruby Smalltalk Perl awk

Slide 4

Slide 4 text

$! $_ $1, $2, $3 BEGIN END .. ...

Slide 5

Slide 5 text

Peak Ruby is Magic Today

Slide 6

Slide 6 text

Nein! Doch! Ohh!

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

$! $_ $1, $2, $3 BEGIN END .. ...

Slide 9

Slide 9 text

$! $_ $1, $2, $3 BEGIN END .. ...

Slide 10

Slide 10 text

.. ... 1..5 1...5 Range

Slide 11

Slide 11 text

SKEPTICAL PINKIE PIE SKEPTICAL PINKIE PIE IS SKEPTICAL IS SKEPTICAL

Slide 12

Slide 12 text

Fun Fact™ if (x == 5)..(x == 10) puts x end Not a Range literal!

Slide 13

Slide 13 text

IS EVEN MOAR SKEPTICAL IS EVEN MOAR SKEPTICAL SKEPTICAL PINKIE PIE SKEPTICAL PINKIE PIE

Slide 14

Slide 14 text

Flip-Flop

Slide 15

Slide 15 text

Flip-Flop In scalar context, ".." returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ".." operator maintains its own boolean state, even across calls to a subroutine that contains it. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. It doesn't become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two. In all other regards, "..." behaves just like ".." does. The right operand is not evaluated while the operator is in the "false" state, and the left operand is not evaluated while the operator is in the "true" state. The precedence is a little lower than || and &&. The value returned is either the empty string for false, or a sequence number (beginning with 1) for true. The sequence number is reset for each range encountered. The final sequence number in a range has the string "E0" appended to it, which doesn't affect its numeric value, but gives you something to search for if you want to exclude the endpoint. You can exclude the beginning point by waiting for the sequence number to be greater than 1. If either operand of scalar ".." is a constant expression, that operand is considered true if it is equal (==) to the current input line number (the $. variable).

Slide 16

Slide 16 text

Quelle: http:/ /perldoc.perl.org/perlop.html#Range-Operators Flip-Flop In scalar context, ".." returns a boolean value. The operator is bistable, like a flip-flop, and emulates the line-range (comma) operator of sed, awk, and various editors. Each ".." operator maintains its own boolean state, even across calls to a subroutine that contains it. It is false as long as its left operand is false. Once the left operand is true, the range operator stays true until the right operand is true, AFTER which the range operator becomes false again. It doesn't become false till the next time the range operator is evaluated. It can test the right operand and become false on the same evaluation it became true (as in awk), but it still returns true once. If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two. In all other regards, "..." behaves just like ".." does. The right operand is not evaluated while the operator is in the "false" state, and the left operand is not evaluated while the operator is in the "true" state. The precedence is a little lower than || and &&. The value returned is either the empty string for false, or a sequence number (beginning with 1) for true. The sequence number is reset for each range encountered. The final sequence number in a range has the string "E0" appended to it, which doesn't affect its numeric value, but gives you something to search for if you want to exclude the endpoint. You can exclude the beginning point by waiting for the sequence number to be greater than 1. If either operand of scalar ".." is a constant expression, that operand is considered true if it is equal (==) to the current input line number (the $. variable). Perl!

Slide 17

Slide 17 text

Ruby Documentation?

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

DON’T KNOW IF REAL FEATURE DON’T KNOW IF REAL FEATURE OR JUST FORGOTTEN TO REMOVE OR JUST FORGOTTEN TO REMOVE

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

(1..5).each do |x| puts x if (x == 2)..(x == 4) end

Slide 22

Slide 22 text

(1..5).each do |x| puts x if (x == 2)..(x == 4) end => 2 3 4

Slide 23

Slide 23 text

(x == 2)..(x == 4) Input

Slide 24

Slide 24 text

x=1 (x == 2)..(x == 4) Input

Slide 25

Slide 25 text

x=1 false (x == 2)..(x == 4) Input

Slide 26

Slide 26 text

x=1 false false (x == 2)..(x == 4) Input

Slide 27

Slide 27 text

x=1 false false (x == 2)..(x == 4) if: false #=> Input

Slide 28

Slide 28 text

x=1 false false (x == 2)..(x == 4) x=2 true false if: false #=> if: true #=> 2 Input

Slide 29

Slide 29 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 false false if: false #=> if: true #=> 2 if: true #=> 3 Input

Slide 30

Slide 30 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 false false x=4 false true if: false #=> if: true #=> 2 if: true #=> 3 if: true #=> 4 Input

Slide 31

Slide 31 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 false false x=4 false true x=5 false false if: false #=> if: true #=> 2 if: true #=> 3 if: true #=> 4 if: false #=> Input

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

In electronics, a flip-flop or latch is a circuit that has two stable states and can be used to store state information. Quelle: https://de.wikipedia.org/wiki/Flipflop

Slide 34

Slide 34 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State

Slide 35

Slide 35 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State !

Slide 36

Slide 36 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State ! " !

Slide 37

Slide 37 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State ! " " !

Slide 38

Slide 38 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State ! " " ! " !

Slide 39

Slide 39 text

x=1 false false (x == 2)..(x == 4) x=2 true false x=3 nil false x=4 nil true x=5 false false if: false if: true if: true if: true if: false Input flip-flop State ! " " ! " ! !

Slide 40

Slide 40 text

Der flip-flop evaluiert immer dann zu true, wenn er aufgeht oder offen war

Slide 41

Slide 41 text

LET’S USE IT THEN! LET’S USE IT THEN!

Slide 42

Slide 42 text

Fiij Buij

Slide 43

Slide 43 text

★ Gebe die Zahl aus ★ Gebe 'Fizz' aus wenn Zahl durch 3 teilbar ★ Gebe 'Buzz' aus wenn Zahl durch 5 teilbar ★ Gebe 'FizzBuzz' aus wenn Zahl durch 3 und 5 teilbar

Slide 44

Slide 44 text

a=b=c = nil # Initialisierung! ! (1..100).each do |num| fizz = true unless (a = !a) .. (a = !a) buzz = true unless (b = !b) ... !((c = !c) .. (c = !c)) ! print_it(num, fizz, buzz) end

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

(a = !a)..(a = !a) a=… flip-flop State

Slide 47

Slide 47 text

(a = !a)..(a = !a) a=… flip-flop State nil

Slide 48

Slide 48 text

(a = !a)..(a = !a) a=… flip-flop State nil true

Slide 49

Slide 49 text

(a = !a)..(a = !a) a=… flip-flop State nil true false

Slide 50

Slide 50 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " !

Slide 51

Slide 51 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " ! false nil true if: true " !

Slide 52

Slide 52 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " ! false nil true if: true " ! true false nil if: false !

Slide 53

Slide 53 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " ! false nil true if: true " ! true false nil if: false ! false true false if: true " !

Slide 54

Slide 54 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " ! false nil true if: true " ! true false nil if: false ! false true false if: true " ! false nil true if: true " !

Slide 55

Slide 55 text

(a = !a)..(a = !a) a=… flip-flop State nil true false if: true " ! false nil true if: true " ! true false nil if: false ! false true false if: true " ! false nil true if: true " ! true false nil if: false !

Slide 56

Slide 56 text

a=b=c = nil # Initialisierung! ! (1..100).each do |num| fizz = true unless (a = !a) .. (a = !a) ! print_it(num, fizz, buzz) end ✔ buzz = true unless (b = !b) ... !((c = !c) .. (c = !c))

Slide 57

Slide 57 text

buzz = true unless (b = !b) ... !((c = !c) .. (c = !c))

Slide 58

Slide 58 text

buzz = true unless (b = !b) ... !((c = !c) .. (c = !c)) (a = !a) .. (a = !a) unless fizz_flipflop

Slide 59

Slide 59 text

(b = !b)...(fizz_flipflop) b=… flip-flop State

Slide 60

Slide 60 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil

Slide 61

Slide 61 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true

Slide 62

Slide 62 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil

Slide 63

Slide 63 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " !

Slide 64

Slide 64 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " ! true nil false if: true "

Slide 65

Slide 65 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " ! true nil false true nil false if: true " if: true "

Slide 66

Slide 66 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " ! true nil false true nil false if: true " true nil true if: true " ! if: true "

Slide 67

Slide 67 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " ! true nil false true nil false if: true " true nil true true false nil if: true " ! if: true " if: false !

Slide 68

Slide 68 text

(b = !b)...(fizz_flipflop) b=… flip-flop State nil true nil if: true " ! true nil false true nil false if: true " true nil true true false nil if: true " ! false true nil if: true " if: false ! if: true " !

Slide 69

Slide 69 text

a=b=c = nil # Initialisierung! ! (1..100).each do |num| fizz = true unless (a = !a) .. (a = !a) buzz = true unless (b = !b) ... !((c = !c) .. (c = !c)) ! print_it(num, fizz, buzz) end ✔

Slide 70

Slide 70 text

a=b=c = nil # Initialisierung! ! (1..100).each do |num| fizz = true unless (a = !a) .. (a = !a) buzz = true unless (b = !b) ... !((c = !c) .. (c = !c)) ! print_it(num, fizz, buzz) end ✔ ✔

Slide 71

Slide 71 text

1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 … a=b=c = nil # Initialisierung! ! (1..100).each do |num| fizz = true unless (a = !a) .. (a = !a) buzz = true unless (b = !b) ... !((c = !c) .. (c = !c)) ! print_it(num, fizz, buzz) end

Slide 72

Slide 72 text

a=b=c=(1..100).each do |num| print num, ?\r, ("Fizz" unless (a = !a) .. (a = !a)), ("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))), ?\n end

Slide 73

Slide 73 text

★ Sehr viel Komplexität ★ Extrem unbekannt ★ Schlecht zu debuggen ★ Für awk/sed Funktionalität „sinnvoll“ d Finger weg!!!

Slide 74

Slide 74 text

Some More Things …

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

ruby.town @ruby_town Ruby-Assemblies-on- Chaos-Communication-Congress-and- Chaos-Communication-Camp

Slide 77

Slide 77 text

Harassment, Misogyny and Hatred against women and minorities in IT and Open Source Harassment, Misogyny and Hatred against women and minorities in IT and Open Source

Slide 78

Slide 78 text

https://modelviewculture.com/support Go to:

Slide 79

Slide 79 text

Thanks! Dirk Breuer / @railsbros_dirk Sebastian Cohnen / @tisba http://geekstammtisch.de QaA “My Little Pony” © Hasbro Studios and DHX Media Vancouver ✗