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
grades = { "Jane Doe" => 10, "Jim Doe" => 6 } | |
options = { :font_size => 10, :font_family => "Arial" } | |
options = { font_size: 10, font_family: "Arial" } | |
options[:font_size] # => 10 | |
grades = Hash.new | |
grades["Dorothy Doe"] = 9 |
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
x = 1 | |
if x > 2 | |
puts "x é maior que 2" | |
elsif x <= 2 and x!=1 | |
puts "x é menor que 2 e diferente de 1" | |
else | |
puts "não sei o valor de x" | |
end | |
x = 1 |
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
for i in 0..5 | |
puts "Value of local variable is #{i}" | |
end | |
i = 0 | |
num = 5 | |
until i > num do | |
puts("Inside the loop i = #{i}" ) | |
i +=1; |
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
#Recebe o primeiro número inteiro | |
num1 = gets.to_i | |
#Recebe o segundo número inteiro | |
num2 = gets.to_i | |
#Soma os números | |
soma = num1 + num2 | |
#Subtrai a soma do primeiro número | |
subtracao = soma - num1 | |
#Multiplica a subtração pelo segundo número | |
multiplicacao = subtracao*num2 |
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
5.times do |i| | |
print i.to_s | |
end | |
#=> 0 1 2 3 4 | |
grades = { "Jane Doe" => 10, "Jim Doe" => 6 } | |
grades.each_with_index do |k, v| | |
print k + " tirou a nota " + v | |
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
class Livro | |
def initialize(autor, titulo, paginas) | |
@autor = autor | |
@titulo = titulo | |
@paginas = paginas | |
#ou | |
@autor, @titulo, @paginas = autor, titulo, paginas | |
end | |
def autor |
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 Livro | |
attr_accessor :autor, :titulo, :paginas | |
def initialize(autor, titulo, paginas) | |
@autor = autor | |
@titulo = titulo | |
@paginas = paginas | |
end | |
def to_s | |
"#{@titulo}, por #{@autor}. #{paginas} páginas." |
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
#Declaracao de vetor | |
nome = [] | |
idade = [] | |
#Estrutura de repeticao para solicitar 5 vezes nome e idade | |
(0..4).each do |x| | |
puts "Digite o nome:" | |
nome << gets.chomp | |
puts "Digite a idade" | |
idade.push(gets.chomp.to_i) |
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
#Declarando Hash | |
pessoas = Hash.new | |
(0..4).each do |x| | |
puts"Digite o nome:" | |
nome = gets.chomp.to_sym | |
puts "Digite a idade:" | |
idade = gets.chomp.to_i | |
#Atribuindo valores ao hash | |
pessoas[nome] = idade; |
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 Animal | |
attr_accessor :especie, :nome, :sexo | |
def initialize(especie, nome, sexo) | |
@especie = especie | |
@nome = nome | |
@sexo = sexo | |
end | |
def to_s | |
"#{@nome}, sexo #{@sexo} da espécie #{@especie}" |