Slide 1

Slide 1 text

MORE Ruby, less Rails Let’s rediscover Ruby together

Slide 2

Slide 2 text

MORE Ruby, less Rails Let’s rediscover Ruby together https://maikhel.github.io Michał Łęcicki

Slide 3

Slide 3 text

before we start…

Slide 4

Slide 4 text

🎓

Slide 5

Slide 5 text

🤷

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

MORE Ruby, less Rails Let’s rediscover Ruby together

Slide 8

Slide 8 text

Ruby Gems

Slide 9

Slide 9 text

Package of Ruby code that provides a speci fi c functionality. Ruby Gems

Slide 10

Slide 10 text

Stdlib Default Gems
 Bundled Gems Native Extensions Independent Gems Ruby Gems

Slide 11

Slide 11 text

Stdlib Math
 Object Socket MakeMake fi le Gem Installed with Ruby Not packed as a separate .gem files Can’t be updated independently of Ruby

Slide 12

Slide 12 text

Default gems Installed with Ruby Can’t be removed Maintained by Ruby core benchmark
 did_you_mean irb singleton prettyprint

Slide 13

Slide 13 text

Bundled gems Installed with Ruby Can be removed or updated Maintained outside of Ruby core abbrev csv minitest
 prime rake

Slide 14

Slide 14 text

Native extensions Require compilation on install Platform dependent pg
 nokogiri mysql2

Slide 15

Slide 15 text

Stdlib Default Gems
 Bundled Gems Native Extensions Independent Gems Ruby Gems

Slide 16

Slide 16 text

Quiz

Slide 17

Slide 17 text

json Default gem ✅

Slide 18

Slide 18 text

test-unit Bundled gem ✅

Slide 19

Slide 19 text

securerandom Default gem ✅

Slide 20

Slide 20 text

minitest Bundled gem ✅

Slide 21

Slide 21 text

rspec A great gem 🌟

Slide 22

Slide 22 text

https://alchemists.io/articles/ruby_default_gems https://stdgems.org/ https://docs.ruby-lang.org/en/3.4/standard_library_md.html

Slide 23

Slide 23 text

Ruby Heredocs

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Ruby heredoc

Slide 28

Slide 28 text

Ruby heredoc

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Squiggly heredoc << ~ ✨

Slide 34

Slide 34 text

Closing tag must not be indented! unless…

Slide 35

Slide 35 text

<< - ✨

Slide 36

Slide 36 text

Ruby Heredocs Starting tag and closing tag must match String interpolation turned on by default <<~ strips indendation << - strips indendation of closing tag https://blog.saeloun.com/2020/04/08/heredoc-in-ruby-and-rails/

Slide 37

Slide 37 text

Ruby Refinements

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Monkey patching 🐒

Slide 41

Slide 41 text

Sub class 👪

Slide 42

Slide 42 text

Ruby Refinement 💎

Slide 43

Slide 43 text

Ruby Refinement 💎

Slide 44

Slide 44 text

Ruby Refinements 💎 You can refine class methods ( refine Date.singleton_class ) You can’t refine constants, nor class variables Monkey Patching a refinement will void the refinement

Slide 45

Slide 45 text

Ruby Refinements 💎 https://alchemists.io/articles/ruby_re fi nements https://github.com/bkuhlmann/re fi nements

Slide 46

Slide 46 text

Variables

Slide 47

Slide 47 text

Local Instance
 Class
 Constants Global Variables

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

$! - latest error message $@ - location of error $_ - string last read by `gets` $. - line number last read by interpreter $& - string last matched by regexp $~ - the last regexp match, as an array of subexpressions $1, $2, ..., $n - the nth subexpression in the last match (same as $~[n]) Special Variables

Slide 50

Slide 50 text

$= - case-insensitivity fl ag $/ - input record separator $\ - output record separator $0 - the name of the Ruby script fi le $* - the command line arguments $$ - interpreter's process ID $? - exit status of last executed child process Special Variables

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

Ensure

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Reserved keywords

Slide 58

Slide 58 text

Words that are part of the language syntax.
 You cannot use them as variable, method or class/module names. Reserved keywords

Slide 59

Slide 59 text

Quiz

Slide 60

Slide 60 text

using Not a keyword ❌

Slide 61

Slide 61 text

BEGIN Reserved keyword ✅

Slide 62

Slide 62 text

Not a keyword ❌ exit

Slide 63

Slide 63 text

private Not a keyword ❌

Slide 64

Slide 64 text

self Reserved keyword ✅

Slide 65

Slide 65 text

try Doesn’t exist in Ruby!

Slide 66

Slide 66 text

Random stuff

Slide 67

Slide 67 text

Enumerable#tally

Slide 68

Slide 68 text

Enumerable#tally

Slide 69

Slide 69 text

Enumerable#tally

Slide 70

Slide 70 text

Enumerable#all?

Slide 71

Slide 71 text

Enumerable#none?

Slide 72

Slide 72 text

Enumerable#any? There is also Enumerable#one?

Slide 73

Slide 73 text

Enumerable#chunk

Slide 74

Slide 74 text

Enumerable#each_slice

Slide 75

Slide 75 text

Enumerable#each_slice

Slide 76

Slide 76 text

Enumerable#slice_before

Slide 77

Slide 77 text

Enumerable#slice_after

Slide 78

Slide 78 text

Enumerable#slice_when

Slide 79

Slide 79 text

Enumerable#zip

Slide 80

Slide 80 text

Enumerable#zip

Slide 81

Slide 81 text

Enumerable#zip

Slide 82

Slide 82 text

Lazy enumerator Ruby operators precedence File IO#open modes Ruby exception classes

Slide 83

Slide 83 text

before we fi nish…

Slide 84

Slide 84 text

https://www.visuality.pl/posts/how-to-become-a-ruby-certified-programmer

Slide 85

Slide 85 text

https://github.com/ruby-association/prep-test/blob/master/silver.md

Slide 86

Slide 86 text

https://maikhel.github.io/about#presentations Thank you!