a programmer's best friendfrank/ine5612/seminario2011.1/ruby.pdf · fernando zimmermann geison...
TRANSCRIPT
![Page 1: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/1.jpg)
Fernando Zimmermann
Geison Machado
Mayco Amorim
Thiago Castro
A programmer's best friend
![Page 2: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/2.jpg)
• Linguagem de programação interpretada
multiparadigma;
• Possui gerenciamento de memória
automático;
• Ruby é totalmente livre.
![Page 3: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/3.jpg)
• Desenvolvida no Japão em 1995,
por Yukihiro Matsumoto;
• Originalmente planejada para ser usada
como linguagem de script;
• Misturou partes de suas linguagens
favoritas (Perl, Smalltalk, Eiffel, Ada e
Lisp).
![Page 4: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/4.jpg)
• Em 2006 atingiu aceitação massiva;
• 12ª posição entre as linguagens de
programação em todo o mundo (índice
TIOBE);
• Ruby on Rails Web Framework.
![Page 5: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/5.jpg)
• Pearl, Python, SmallTalk
• Ponto e vírgula
• Identação
• Escopo das variáveis
• attr_writer
• attr_reader
![Page 6: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/6.jpg)
puts "Hello World"
class HelloWorld
def show_me
puts "Hello World"
end
end
hw = HelloWorld.new
hw.show_me
![Page 7: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/7.jpg)
• Ruby forge
• Ruby Application Archive(RAA)
• RubyGems
![Page 8: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/8.jpg)
• Programador, produtividade e diversão
• Voltado ao programador, não à maquina
• Linguagens são uma expressão dos nossos
pensamentos.
• Pessoas são boas em:
• Cometer erros, criação, Imaginação
• Pessoas são ruins em:
• Fazer cópias, trabalhos tediosos, cálculos
rápidos
• Segue o POLA ( Principle of Least Astonishment )
• Pirinciple of Succincteness ( Principio de concisão )
![Page 9: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/9.jpg)
• Suporte a Unicode ainda é considerado bastante
cheio de bugs
• É uma linguagem relativamente nova
• Linguagem interpretada
• Execução mais lenta do que linguagens
compiladas
• Just in time compilation
• Rápida, mas não tão rápida quanto poderia ser.
• Atualizações previstas para a versão 2.0
![Page 10: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/10.jpg)
• Rails é um framework que facilitou a
utilização do Ruby para CRUD e outras
necessidades;
• Principal responsável pelo sucesso do
Ruby.
![Page 11: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/11.jpg)
• Objetivos diferentes;
• Paradigmas;
• Compilação;
• Facilidade de aprendizado:
tryruby.org e rubyforzombies.org
![Page 12: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/12.jpg)
• Repositório unificado na internet;
• Download similar ao apt e yum;
• Rake;
• Repositório: http://rubygems.org/
![Page 13: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/13.jpg)
• Existem solução não estáveis que
compilam o script em ruby para
linguagem C;
• Soluções Jruby;
![Page 14: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/14.jpg)
• Twitter;
• BaseCamp (37 Signals);
• Scribd;
• GitHub;
• Hulu.
![Page 15: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/15.jpg)
• Isso é uma variável de instância: @teste
• Isso é uma variável local: oque='vishi'
• Isso é uma variável global: $i=0
![Page 16: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/16.jpg)
• Primeiro hello world em ruby
Simples: puts → comando pra impressão
puts “hello world”
![Page 17: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/17.jpg)
• A sintaxe de Ruby não usa chaves nem
ponto e virgula para organização do
corpo da classe, ela usa o comando 'end'
para isso:
Class classe
#blablabla
End
• O cerquilha define um comentário, Class
define que eh uma classe e end neste
caso, é o fim da classe
![Page 18: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/18.jpg)
#esse eh um metodo
def oque?
puts “meu metodo”
end
#metodo com parametro
def escrevemuito(ateonde)
i=0
while i < ateonde
puts “passei aqui”+i.to_s
end
![Page 19: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/19.jpg)
• Foi necessário adicionar '.to_s' um
método acessivel a todos os objetos em
Ruby, para poder transformar o inteiro 'I'
em para string, pois do contrário não
concatenaria string com int “passei
aqui”+i.to_s
• Em casos de valores string serem
parseados para int seria '3'.to_i
![Page 20: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/20.jpg)
Ex.:
class Teste
def initialize(value)
@value = value
end
end
Construtor passando valor para variavel de instancia
![Page 21: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/21.jpg)
Atribuição simples:
MeuArr=[1,'m',2,5,'y',1,9,10]
MeuArr.each{|e| puts e.to_s}
for i in 0 ... MeuArr.length
puts i.to_s
end
i=0
while i < a
puts MeuArr[i].to_s
i+=1
end
![Page 22: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/22.jpg)
def fatorial(number)
if (number < 2)
return number
else
return number * fatorial(number
- 1)
end
end
O return é usado apenas quando o retorno
não está no final do método
![Page 23: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/23.jpg)
teste = Teste.new(proconstrutor)
Import para classe:
require 'Teste.rb'
Usar metodo da classe:
teste.metodo(parametro)
teste.metodo2
Arquivos Ruby têm extensão de arquivo:
'rb'
![Page 24: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/24.jpg)
• Ruby pode ser executado no terminal
linux com o comando 'ruby
nomeclasse.rb'
• Ou editando no proprio terminal com a
ferramenta 'irb'
![Page 25: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/25.jpg)
class Teste
def initialize(valor)
@valor = valor
end
def getValor
@valor
end
end
![Page 26: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/26.jpg)
require 'Teste.rb'
teste=Teste.new(“olah”)
puts teste.getValor
![Page 27: A programmer's best friendfrank/INE5612/Seminario2011.1/Ruby.pdf · Fernando Zimmermann Geison Machado Mayco Amorim Thiago Castro A programmer's best friend](https://reader030.vdocument.in/reader030/viewer/2022040812/5e57393080b1c62afd03d1cc/html5/thumbnails/27.jpg)
http://www.ruby-lang.org/en/documentation/ruby-from-other-
languages/to-ruby-from-java/
http://www.ruby-lang.org/en/documentation/quickstart/
http://www.ruby-lang.org/en/about/
http://terramel.org/aulas-de-ruby-uma-breve-introducao/
http://ruby-br.org/?page_id=15
http://en.wikipedia.org/wiki/Ruby_(programming_language)
http://www.rubyonbr.org/articles/2006/08/24/programa-helloworld-em-
ruby/
http://ruby-br.org
http://www.ruby-lang.org
http://www.slideshare.net/vishnu/the-ruby-programming-language-or-
why-are-you-wasting-brain-power?src=related_normal&rel=626067