introdução à programação em ruby
TRANSCRIPT
![Page 1: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/1.jpg)
![Page 2: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/2.jpg)
Quem sou eu?
Daniel Coelho de Andrade
Graduando em Engenharia de Computação - UEFS
Membro da Empresa Júnior de Engenharia de Computação da UEFS
![Page 3: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/3.jpg)
“Ruby”?
● Linguagem dinâmica● Foco na simplicidade e produtividade● Leitura natural● Multiparadigma e propósito geral● Scripts● Interpretada
![Page 4: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/4.jpg)
Um pouco de história...
● Criador: Yukihiro Matsumoto - “Matz”
● Primeira versão estável: 1996
● Versão atual (estável): 2.2.0
![Page 5: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/5.jpg)
“Ruby is simple in appearance, but is very complex inside, just like the human body” – Matz
![Page 6: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/6.jpg)
...mais uma linguagem?
● Matz queria uma linguagem que...– Fosse mais poderosa que o Pearl– Mais orientada a objetos que Python– Simples como o Lisp
![Page 7: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/7.jpg)
“Por que aprender Ruby?”
![Page 8: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/8.jpg)
codeeval.com - 2014
![Page 9: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/9.jpg)
![Page 10: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/10.jpg)
“Mas Ruby é lento...”
![Page 11: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/11.jpg)
Fonte: programmingzen.com/?s=benchmark
![Page 12: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/12.jpg)
Fonte: bjpelc.wordpress.com
![Page 13: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/13.jpg)
Está melhorando muito!
![Page 14: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/14.jpg)
“Quero saber quem é que usa isso aí”
![Page 15: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/15.jpg)
![Page 16: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/16.jpg)
![Page 17: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/17.jpg)
![Page 18: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/18.jpg)
![Page 19: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/19.jpg)
Esse são só alguns...
![Page 20: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/20.jpg)
Então...
![Page 21: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/21.jpg)
Porque programar em Ruby?
● Fácil leitura● Foco na simplicidade e produtividade● Comunidade● Desenvolvimento Ágil (Framework Rails)● Sempre tem mais de um jeito de fazer a
mesma coisa● É divertido :)
![Page 22: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/22.jpg)
Além disso...
![Page 23: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/23.jpg)
Interactive Ruby Shell
![Page 24: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/24.jpg)
RubyGems
![Page 25: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/25.jpg)
#gem install sqlite3
![Page 26: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/26.jpg)
Só mais uma coisa...
![Page 27: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/27.jpg)
Ruby is evil
![Page 28: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/28.jpg)
“O Ruby é mal. Muito mal. Mas por que é tão mal? Porque é tão bonito. A sintaxe é tão elegante, tudo é objeto, tudo faz sentido. O jeito Ruby de fazer as coisas é tão atraente...”
Simon Eskildsen
Responsável pela infraestrutura do Shopify
![Page 29: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/29.jpg)
“Sim, tá falando demais”
![Page 30: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/30.jpg)
Ok, chega. Vamos programar!
![Page 31: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/31.jpg)
“Mas espera, como instala isso aí?”
![Page 32: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/32.jpg)
No Windows
● Faça o download do executável em http://rubyinstaller.org/
● Instale
![Page 33: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/33.jpg)
No Linux
● Distribuições baseadas no Red Hat– sudo yum install ruby irb rubygems
● Distribuições baseadas no Debian– sudo apt-get install ruby irb rubygems
![Page 34: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/34.jpg)
“O que vamos usar para programar em Ruby?”
![Page 35: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/35.jpg)
Ferramentas
● IRB
● Terminal
● Um editor de texto
![Page 36: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/36.jpg)
“Como abro o IRB?”
![Page 37: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/37.jpg)
Fácil!
● Abra o Terminal(ctrl+alt+t)
● Digite irb
![Page 38: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/38.jpg)
Tradições...
![Page 39: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/39.jpg)
No IRB...
puts “Hello, World!”
print “Hello, World!”
p “Hello, World!”
![Page 40: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/40.jpg)
Comentários
![Page 41: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/41.jpg)
Variáveis
![Page 42: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/42.jpg)
Não precisa declará-las
![Page 43: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/43.jpg)
O Ruby é dinâmico!
![Page 44: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/44.jpg)
“Não entendi o 'dinâmico'...”
![Page 45: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/45.jpg)
Vamos entender na a prática então
![Page 46: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/46.jpg)
No IRB...
![Page 47: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/47.jpg)
“E se eu quiser imprimir uma variável junto a um texto?”
![Page 48: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/48.jpg)
Simples, é só interpolar
![Page 49: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/49.jpg)
Exemplo
numero = 42
puts “Eu escolhi o número #{numero}”
![Page 50: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/50.jpg)
Sua vez
Escolha um número qualquer, atribua ele a uma variável e imprima a mensagem “O
número (seu número) foi escolhido por mim”
![Page 51: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/51.jpg)
![Page 52: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/52.jpg)
“nil?”
![Page 53: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/53.jpg)
Convenções
● CONSTANTE
● variavelComMaisDeUmNome
![Page 54: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/54.jpg)
Vamos para algo um pouco mais interessante...
![Page 55: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/55.jpg)
Strings
![Page 56: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/56.jpg)
Strings
● Array de sequência de bytes
● “String” é diferente de 'String'
● “a” é uma String– Não existem caracteres
![Page 57: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/57.jpg)
Lidando com Strings
● nome.upcase● nome.downcase● nome.capitalize● nome.swapcase● nome.reverse● Vários outros...
![Page 58: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/58.jpg)
Sim, parênteses são opcionais!
![Page 59: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/59.jpg)
Voltando...
![Page 60: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/60.jpg)
Transformando Strings
![Page 61: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/61.jpg)
Strings são mutáveis
![Page 62: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/62.jpg)
“Sempre existe mais de um jeito de fazer a mesma coisa”
![Page 63: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/63.jpg)
Jeito “comum”
nome=nome.capitalize
![Page 64: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/64.jpg)
Jeito Ruby
nome.capitalize!
![Page 65: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/65.jpg)
![Page 66: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/66.jpg)
“O “!” funciona pra qualquer método?”
![Page 67: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/67.jpg)
“Como leio dados do teclado?”
![Page 68: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/68.jpg)
Fácil!
● gets
● gets.chomp
![Page 69: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/69.jpg)
“Tá ficando chato fazer isso no Shell...”
![Page 70: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/70.jpg)
“Como crio arquivos executáveis em Ruby?”
![Page 71: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/71.jpg)
Criando, Editando e Executando
● Arquivo de texto com extensão .rb
● ruby seuarquivo.rb
![Page 72: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/72.jpg)
Para fixar o conhecimento...
Faça um programa que leia uma string e imprima essa string ao contrário.
![Page 73: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/73.jpg)
Fluxo de Controle
![Page 74: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/74.jpg)
Comparando com C e Java...
● else if = elsif
● Sem chaves obrigatórias
● O bloco é finalizado com a palavra end
![Page 75: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/75.jpg)
Operadores lógicos
● || ou or = ou
● and ou && = e
● not = negação
![Page 76: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/76.jpg)
Exemplo
![Page 77: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/77.jpg)
Escrito de outro jeito...
![Page 78: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/78.jpg)
Compactando
![Page 79: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/79.jpg)
Exercício para fixar a sintaxe :)
![Page 80: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/80.jpg)
Um programa que lê uma string digitada pelo usuário e substitui todas letras “a” por um “-”
Alguma sugestão de como fazer?
![Page 81: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/81.jpg)
![Page 82: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/82.jpg)
Vamos tentar de novo...
![Page 83: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/83.jpg)
gsub(“a”, “b”)
include?()
![Page 84: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/84.jpg)
Agora sim!
Um programa que lê uma string digitada pelo usuário e substitui todas letras “a” por um “-”
![Page 85: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/85.jpg)
![Page 86: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/86.jpg)
Loops e Iteradores
![Page 87: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/87.jpg)
While
![Page 88: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/88.jpg)
x++? não
![Page 89: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/89.jpg)
x+=1
![Page 90: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/90.jpg)
For
![Page 91: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/91.jpg)
1..5? Intervalos!
● 1..5 = 1,2,3,4,5● 1...5 = 1,2,3,4
● Também funciona com letras!
![Page 92: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/92.jpg)
“Jeito Ruby de fazer as coisas...”
![Page 93: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/93.jpg)
Until
![Page 94: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/94.jpg)
.times
![Page 95: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/95.jpg)
.upto
![Page 96: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/96.jpg)
.downto
![Page 97: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/97.jpg)
Antes de falarmos sobre Iteradores...
![Page 98: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/98.jpg)
Arrays
![Page 99: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/99.jpg)
Instanciando
● array = []
● array = Array.new
● array=Array.new(tamanho)
● array=Array.new(tamanho, elemento)
![Page 100: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/100.jpg)
Acessando os elementos
● Index [x]● Intervalos [x..y] ou [x...y]● array.first● array.last● array.take(n)● array.length● array.include?
![Page 101: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/101.jpg)
Adicionando elementos
● array.push(dado)● array << dado● array.insert(posição, dado)
![Page 102: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/102.jpg)
Removendo elementos
● array.delete● array.delete_at(posicao)● array.pop
![Page 103: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/103.jpg)
Soma e Subtração
![Page 104: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/104.jpg)
![Page 105: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/105.jpg)
“E lista?”
![Page 106: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/106.jpg)
Lista == Array
![Page 107: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/107.jpg)
Agora sim, Iterando em Arrays
![Page 108: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/108.jpg)
Each
array.each{|variavel| comandos}
array.each do |variavel|
comandos
end
![Page 109: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/109.jpg)
![Page 110: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/110.jpg)
Ou..
![Page 111: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/111.jpg)
“Quer dizer que Ruby aceita blocos de comando como parâmetro?”
![Page 112: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/112.jpg)
“Qual a diferença entre o uso das chaves e do 'do...end'?”
![Page 113: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/113.jpg)
Selecionando itens do Array
![Page 114: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/114.jpg)
O problema
Eu tenho um array de strings e quero imprimir somente as strings que começam com vogais,
como faço?
![Page 115: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/115.jpg)
Alguma ideia?
![Page 116: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/116.jpg)
A solução
string.select
array.include?
![Page 117: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/117.jpg)
![Page 118: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/118.jpg)
![Page 119: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/119.jpg)
Definindo suas funções
![Page 120: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/120.jpg)
Corpo de uma função em Ruby
![Page 121: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/121.jpg)
Detalhes...
![Page 122: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/122.jpg)
Em Ruby, toda função retorna um valor
![Page 123: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/123.jpg)
Voltando um pouco...
![Page 124: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/124.jpg)
“Sim, mas o que é esse nil?”
![Page 125: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/125.jpg)
Qual o retorno desse método?
![Page 126: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/126.jpg)
Retorno explícito
![Page 127: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/127.jpg)
Retorno implícito
![Page 128: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/128.jpg)
Convenções
● Se a função retorna true/false, termina em ?
● Se o a função tiver nome composto, separa-os por _
![Page 129: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/129.jpg)
Exemplos
● e_par?● e_impar?● mais_uma_funcao
![Page 130: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/130.jpg)
“Como é aquela coisa de passar blocos como parâmetro?”
![Page 131: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/131.jpg)
yield
![Page 132: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/132.jpg)
![Page 133: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/133.jpg)
Qual a saída desse código?
![Page 134: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/134.jpg)
![Page 135: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/135.jpg)
Pra fixar o conhecimento...
● Faça uma função que aceite um array como parâmetro e, quando dado um bloco, imprima cada um dos elementos do array.
Dicas: Para passar um array como parâmetro usa um * antes do nome da variável. Para verificar se foi
passado um bloco como parâmetro, use a função block_given?
![Page 136: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/136.jpg)
![Page 137: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/137.jpg)
Perguntas?
![Page 138: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/138.jpg)
Próximos tópicos
● POO com Ruby
● Metaprogramação
● Rails
![Page 139: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/139.jpg)
Iniciando com o básico...
![Page 140: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/140.jpg)
Definindo uma classe
![Page 141: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/141.jpg)
Instanciando uma Classe
![Page 142: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/142.jpg)
Observações
● Nome de classe inicia sempre com letra maíuscula
● ClasseComMaisDeUmNome
![Page 143: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/143.jpg)
Antes de continuar vamos ver algumas coisas...
![Page 144: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/144.jpg)
Tudo é objeto
![Page 145: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/145.jpg)
Até as classes são objetos!
![Page 146: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/146.jpg)
![Page 147: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/147.jpg)
![Page 148: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/148.jpg)
As classes são abertas
![Page 149: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/149.jpg)
“Classes abertas???”
![Page 150: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/150.jpg)
![Page 151: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/151.jpg)
![Page 152: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/152.jpg)
Vamos mostrar isso na prática :)
![Page 153: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/153.jpg)
Redefinindo a Classe Class
Live Coding
![Page 154: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/154.jpg)
Isso é chamado de Metaprogramação
![Page 155: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/155.jpg)
“Se tudo é objeto, o que acontece numa expressão do tipo x = 2+2?”
![Page 156: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/156.jpg)
x= 2+ 2
![Page 157: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/157.jpg)
x= 2+ 2
Chamada de método 1
Chamada de método 2
![Page 158: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/158.jpg)
x= 2+ 2
Parâmetro do método 1
Parâmetro do método 2
![Page 159: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/159.jpg)
Lembra? Parênteses são opcionais!
![Page 160: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/160.jpg)
Rearranjando...
![Page 161: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/161.jpg)
x=(2+(2))
![Page 162: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/162.jpg)
x=(4)
![Page 163: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/163.jpg)
“Mas como assim '+' e '=' são métodos?”
![Page 164: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/164.jpg)
Syntax Sugar
![Page 165: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/165.jpg)
Poetry Mode
Fonte: courses.edx.org
![Page 166: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/166.jpg)
“Como posso ver todos os métodos dessas classes?”
![Page 167: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/167.jpg)
ruby-doc.org
![Page 168: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/168.jpg)
.methods
![Page 169: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/169.jpg)
.respond_to?(:nomeDoMetodo)
![Page 170: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/170.jpg)
Níveis de acesso das variáveis
![Page 171: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/171.jpg)
● $var -> Variável global
● @var -> Variável de instância (atributo)
● @@var -> Variável de classe
![Page 172: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/172.jpg)
Todos os atributos são privados
![Page 173: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/173.jpg)
Métodos
![Page 174: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/174.jpg)
● São públicos por padrão
● São divididos em seções de visibilidade
● Ruby não suporta sobrecarga de métodos
![Page 175: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/175.jpg)
![Page 176: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/176.jpg)
Parâmetros opcionais
![Page 177: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/177.jpg)
![Page 178: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/178.jpg)
Chamada sem parâmetro
Chamada com parâmetro
![Page 179: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/179.jpg)
Métodos de Classe
Definindo
Acessando
![Page 180: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/180.jpg)
Convenções sobre métodos
● metodo_com_mais_de_um_nome
● Atribuicao=
● retorno_booleano?
![Page 181: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/181.jpg)
Construindo uma classe simples
![Page 182: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/182.jpg)
![Page 183: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/183.jpg)
Atribuição Condicional
![Page 184: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/184.jpg)
Como você faria os métodos para alterar o endereco de uma pessoa?
![Page 185: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/185.jpg)
“Jeito Ruby”
![Page 186: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/186.jpg)
![Page 187: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/187.jpg)
Código gerado na classe
![Page 188: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/188.jpg)
“E se eu quiser só ler ou alterar o atributo?”
![Page 189: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/189.jpg)
Equivale a
![Page 190: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/190.jpg)
Exercício para fixar a sintaxe
![Page 191: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/191.jpg)
● Classe Telefone(numero:String, crédito:inteiro)● Métodos
– Ligar(número:String) [Desconta 5 créditos por ligação)
– Adicionar créditos
– Total de Telefones [Retorna o total de telefones]
● Obs: Se não for passado um valor, os créditos iniciam em quantidade igual a 50.
● Obs²: A ligação só pode ser feita se os créditos forem suficientes
![Page 192: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/192.jpg)
“Ok. Como faço uma classe herdar de outra?”
![Page 193: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/193.jpg)
![Page 194: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/194.jpg)
Observações sobre Herança
● Ruby não suporta herança múltipla
● Simula herança múltipla por mixins
![Page 195: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/195.jpg)
Antes do mixin propriamente dito...
![Page 196: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/196.jpg)
Modules
Maneira de agrupar métodos, variáveis e constantes
![Page 197: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/197.jpg)
![Page 198: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/198.jpg)
![Page 199: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/199.jpg)
![Page 200: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/200.jpg)
Include vs Require
![Page 201: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/201.jpg)
Mixin é o resultado da inclusão de um module em uma classe.
![Page 202: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/202.jpg)
“Como importo classes em outros arquivos .rb?”
![Page 203: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/203.jpg)
require_relative “caminho/para/arquivo”
![Page 204: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/204.jpg)
Outro exercício
● Crie um Module chamado Motor e uma classe chamada Veículo. Em module, defina os métodos “Ligar” e “Desligar”, que devem imprimir “Motor ligado” e “Motor ligado”, respectivamente. Faça um mixin com a classe Veiculo e o Module Motor.
![Page 205: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/205.jpg)
Mais metaprogramação!
![Page 206: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/206.jpg)
Criando métodos que criam métodos
Temos uma classe professor e temos uma classe aluno. Como fazemos para o professor
ensinar ao aluno a escrever?
![Page 207: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/207.jpg)
Primeiro passo: Classe Aluno
![Page 208: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/208.jpg)
Segundo passo: Classe Professor
![Page 209: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/209.jpg)
Terceiro passo: Classe Aula
![Page 210: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/210.jpg)
Fonte do Exercício: Caelum
![Page 211: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/211.jpg)
Exercício
Crie uma classe Superman e uma classe Pessoa. Faça com que Superman ensina uma
pessoa a voar numa Aula. Superman, Pessoa e Aula devem estar em arquivos separados.
![Page 212: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/212.jpg)
Desvantagens do Ruby
![Page 213: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/213.jpg)
● Ainda é considerado lento
● Pouco material disponível comercialmente
● Codificação única
![Page 214: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/214.jpg)
Com Ruby, evite:
● Aplicações com processamento tempo real
● Aplicações que exigem muito processamento
![Page 215: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/215.jpg)
Perguntas?
![Page 216: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/216.jpg)
Onde encontrar mais:
● Ruby-lang.org● Manual Ruby TAC● Sirupsen.com – Simon Eskildsen● Akita On Rails – Fábio Akita● Caelum
![Page 217: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/217.jpg)
Isso é tudo, Obrigado :)
![Page 218: Introdução à programação em Ruby](https://reader030.vdocuments.site/reader030/viewer/2022020123/55ab537d1a28ab12208b481d/html5/thumbnails/218.jpg)