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 |
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
even_numbers = {} # Cria um objeto hash vazio | |
even_numbers["zero"] = 0 # Atribui 0 como valor para a chave "zero" | |
even_numbers["two"] = 2 | |
even_numbers["four"] = 4 | |
even_numbers["two"] # Recupera 2 como valor |
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
calc = ShippingCalculator.new | |
calc.calculate 1.50, :height => 0.75, :width => 1.00, :depth => 0.10 |
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" |
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 |
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
my_proc = Proc.new { |x, y| x * y } |
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
def some_method | |
puts "Início do método" | |
my_proc = Proc.new do |message| | |
puts "Dentro do proc: #{message}" | |
return | |
end | |
my_proc.call "Ruby Fundamental" | |
puts "Fim do método" # Essa linha não é executada |
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 FreteCorreios | |
def calcular | |
# Implementação do método | |
end | |
end | |
class FreteFedex | |
def calcular | |
# Implementação do método | |
end |
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
module CoolModule | |
def do_something | |
"I did it!" | |
end | |
end | |
class SomeClass | |
include CoolModule | |
end |
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
module Numbers | |
def one | |
puts "1" | |
end | |
def two | |
puts "2" | |
end | |
end |