View blocks_procs_lambdas.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Difference between blocks, procs and lambdas. | |
Blocks are not objects and can't be manipulates as objects. With procs and lambdas is possible to | |
create objects that represents a block. | |
Procs and lambdas have the 'call' method, that executes the block code associated in their creation. | |
A proc behaves like a block, different of lambdas that behaves like a method. For that reason, | |
lambdas need to receive the exact number of parameters defined in your declaration. |
View ramos_de_atividade.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# ramos_de_atividade.rb | |
nomes = File.readlines("ramos_de_atividade.txt") | |
File.open("ramos_de_atividade.yaml", "w") do |f| | |
nomes.each_with_index do |nome, i| | |
f.puts "ramo_de_atividade_#{i+1}" | |
f.puts " id: #{i+1}" | |
f.puts " nome: #{nome}\n" |
View listar_contatos.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# listar_contatos.rb | |
raise ArgumentError, "=> Quantidade de argumentos incorreta. Exemplo de uso: ruby listar_contatos.rb root minhasenha" if ARGV.size != 2 | |
mysql_user, mysql_pass = ARGV | |
def criar_array(resultado) | |
resultado.split("\n").drop(1) | |
end |
View ramos_de_atividade.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ramo_de_atividade_1 | |
id: 1 | |
nome: Alimentos e Bebidas | |
ramo_de_atividade_2 | |
id: 2 | |
nome: Arte e Antiguidades | |
ramo_de_atividade_3 | |
id: 3 |
View saudacao.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Saudacao | |
def initialize(name) | |
@name = name | |
end | |
def saudar | |
"Bem vindo, #{@name}!" | |
end | |
end |
View classes_11.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
def bark | |
puts "#{@name}: Au, au, au!" | |
end | |
def sleep |
View blocos_1.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greet { puts "Hello" } |
View classes_01.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
end |
View atributos_11.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
attr_accessor :name, :breed | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
# Os demais métodos foram omitidos | |
end |
View atributos_01.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog | |
def initialize(name, breed) | |
@name, @breed = name, breed | |
end | |
def bark | |
puts "#{@name}: Au, au, au!" | |
end | |
def sleep |
OlderNewer