Slide 1

Slide 1 text

Hello Ruby :) Felipe Pelizaro Gentil @fpgentil Carlos Eduardo Ribeiro @duduribeiro

Slide 2

Slide 2 text

ruby /ˈruːbi/

Slide 3

Slide 3 text

Ruby ..is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. https://www.ruby-lang.org/en/documentation/

Slide 4

Slide 4 text

Reserved words

Slide 5

Slide 5 text

Ruby Version Manager (RVM) RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 $ curl -sSL https://get.rvm.io | bash -s stable https://github.com/rvm/rvm

Slide 6

Slide 6 text

IRB … stands for “interactive Ruby” and is a tool to interactively execute Ruby expressions read from the standard input. $ irb

Slide 7

Slide 7 text

Methods

Slide 8

Slide 8 text

if / unless

Slide 9

Slide 9 text

Loops

Slide 10

Slide 10 text

or || && and http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/ and is useful for chaining related operations together until one of them returns nil or false or is useful for chaining expressions together. The best way to think about the chains constructed with or is as series of fallbacks: try this, if that fails try this, and so on. For instance:

Slide 11

Slide 11 text

||= Double Pipe / Or Equals http://www.rubyinside.com/what-rubys-double-pipe-or-equals-really-does-5488.html

Slide 12

Slide 12 text

Array

Slide 13

Slide 13 text

Hash

Slide 14

Slide 14 text

Symbols Symbol objects represent names and some strings inside the Ruby interpreter

Slide 15

Slide 15 text

map http://railspikes.com/2008/8/11/understanding-map-and-reduce Returns a new array with the results of running block once for every element in enum. http://apidock.com/ruby/Enumerable/map

Slide 16

Slide 16 text

reduce / inject http://railspikes.com/2008/8/11/understanding-map-and-reduce Combines all elements of enum by applying a binary operation, specified by a block or a symbol that names a method or operator.

Slide 17

Slide 17 text

reduce / inject http://apidock.com/ruby/v1_9_3_392/Enumerable/inject

Slide 18

Slide 18 text

attr_accessor attr_writer attr_reader defines getter and setter defines only getter defines only setter

Slide 19

Slide 19 text

Classes

Slide 20

Slide 20 text

Opening Classes

Slide 21

Slide 21 text

Clojures function that can be stored as a variable

Slide 22

Slide 22 text

Ruby and its 4 types of clojures Blocks Procedures (aka Procs) lambdas Method Objects

Slide 23

Slide 23 text

Blocks

Slide 24

Slide 24 text

Procedures (Procs) a block that can be saved for reusable code

Slide 25

Slide 25 text

lambdas • a Proc that check the number of arguments • Diminutive return, in other words, a Proc return will stop 
 a method, lambdas will return their value and let the method 
 continue

Slide 26

Slide 26 text

Method Objects

Slide 27

Slide 27 text

Exercises • Generate a Fibonacci sequence in an array until 500 • Create a method that receives N parameter and return their sum • Create a method that receives a string and check if its a palindrome

Slide 28

Slide 28 text

Fibonacci

Slide 29

Slide 29 text

Sum

Slide 30

Slide 30 text

Palindrome

Slide 31

Slide 31 text

Gems • What? essentially a Ruby plugin • Why? code reuse as open-source, it provides others the opportunity
 to contribute by adding features • How? $ gem install bundler $ bundle gem my_gem

Slide 32

Slide 32 text

RubyGems

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Tests!!!!!!!!

Slide 35

Slide 35 text

Rspec / Minitest http://tenderlovemaking.com/2015/01/23/my-experience-with-minitest-and-rspec.html

Slide 36

Slide 36 text

Rspec / Minitest https://github.com/rspec/rspec https://github.com/seattlerb/minitest

Slide 37

Slide 37 text

Exercise Create a GEM that performs the 4 basic math operations - SUM - SUBTRACTION - MULTIPLICATION - DIVISION Tip: folder already created ~/Desktop/Hello Ruby/hello_ruby_calculator

Slide 38

Slide 38 text

No content