summaryrefslogtreecommitdiffhomepage
path: root/pt-br/ruby-pt.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'pt-br/ruby-pt.html.markdown')
-rw-r--r--pt-br/ruby-pt.html.markdown79
1 files changed, 9 insertions, 70 deletions
diff --git a/pt-br/ruby-pt.html.markdown b/pt-br/ruby-pt.html.markdown
index cedd2db1..732d06a4 100644
--- a/pt-br/ruby-pt.html.markdown
+++ b/pt-br/ruby-pt.html.markdown
@@ -9,19 +9,13 @@ contributors:
# Isso é um comentario
=begin
-This is a multiline comment
-No-one uses them
-You shouldn't either
-
-Isso é um comentario multilinha
+Isso é um comentário multilinha
Ninguém os usa
-
+Você não deve usar também
=end
-# First and foremost: Everything is an object.
# Primeiro e principal: Tudo é um objeto.
-# Numbers are objects
# Números são objetos
3.class #=> Fixnum
@@ -29,8 +23,7 @@ Ninguém os usa
3.to_s #=> "3"
-# Some basic arithmetic
-# Aritmética básica
+# Um pouco de aritmética básica
1 + 1 #=> 2
8 - 1 #=> 7
@@ -44,7 +37,6 @@ Ninguém os usa
1.+(3) #=> 4
10.* 5 #=> 50
-# Special values are objects
# Valores especiais são obejetos
nil # Nothing to see here
nil # Nada para ver aqui
@@ -57,26 +49,22 @@ nil.class #=> NilClass
true.class #=> TrueClass
false.class #=> FalseClass
-# Equality
# Igualdade
1 == 1 #=> true
2 == 1 #=> false
-# Inequality
# Desigualdade
1 != 1 #=> false
2 != 1 #=> true
!true #=> false
!false #=> true
-# apart from false itself, nil is the only other 'falsey' value
# além de 'false', 'nil' é o único outro valor falso
!nil #=> true
!false #=> true
!0 #=> false
-# More comparisons
# Mais comparações
1 < 10 #=> true
1 > 10 #=> false
@@ -84,7 +72,6 @@ false.class #=> FalseClass
2 >= 2 #=> true
# Strings are objects
-# Strings são obejetos
'I am a string'.class #=> String
'Eu sou uma string'.class #=> String
@@ -95,47 +82,35 @@ placeholder = "use string interpolation"
placeholder = "usar interpolação de string"
"I can #{placeholder} when using double quoted strings"
"Eu posso #{placeholder} quando estiver usando aspas duplas"
-#=> "I can use string interpolation when using double quoted strings"
#=> "Eu posso usar insterpolação de string quando estiver usando aspas duplas"
-
-# print to the output
-# imprime para output (saida)
+# imprime para output (saída)
puts "I'm printing!"
puts "Estou imprimindo"
-# Variables
# Variáveis
x = 25 #=> 25
x #=> 25
-# Note that assignment returns the value assigned
# Note que uma atribuição retorna o valor atribuido
-# This means you can do multiple assignment:
-# Isso significa que você pode fazer multiplas atribuições:
+# Isso significa que você pode fazer múltiplas atribuições:
x = y = 10 #=> 10
x #=> 10
y #=> 10
-# By convention, use snake_case for variable names
# Por convenção, use snake_case para nomes de variáveis
snake_case = true
-# Use descriptive variable names
# Use nomes de variáveis descrivos
path_to_project_root = '/good/name/'
caminho_para_a_raiz_do_projeto = '/bom/nome/'
path = '/bad/name/'
caminho = '/nome/ruim/'
-# Symbols (are objects)
# Simbolos (são objetos)
-# Symbols are immutable, reusable constants represented internally by an
# Simbolos são imultáveis, são constantes reutilizáveis representadadas internamente por um
-# integer value. They're often used instead of strings to efficiently convey
# valor inteiro. Eles são frequentemente usados no lugar de strings para transmitir com eficiência os valores
-# specific, meaningful values
# específicos e significativos
:pending.class #=> Symbol
@@ -155,68 +130,52 @@ status == :aprovado #=> false
# Arrays
-# This is an array
# Isso é um array
[1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
-# Arrays can contain different types of items
# Arrays podem conter diferentes tipos de itens
array = [1, "hello", false] #=> => [1, "hello", false]
array = [1, "Oi", false] #=> => [1, "Oi", false]
-# Arrays can be indexed
# Arrays podem ser indexados
-# From the front
# a partir do começo
array[0] #=> 1
array[12] #=> nil
-# Like arithmetic, [var] access
# Como aritimetica, o acesso via [var]
-# is just syntactic sugar
# é apenas açúcar sintático
-# for calling a method [] on an object
# para chamar o método [] de um objeto
array.[] 0 #=> 1
array.[] 12 #=> nil
-# From the end
# a partir do final
array[-1] #=> 5
-# With a start and end index
# Com um índice de começo e fim
array[2, 4] #=> [3, 4, 5]
-# Or with a range
# Ou com um intervalo de valores
array[1..3] #=> [2, 3, 4]
-# Add to an array like this
# Adicionar a um array como este
array << 6 #=> [1, 2, 3, 4, 5, 6]
-# Hashes are Ruby's primary dictionary with keys/value pairs.
-# Hashes são dicionário com um par de chave(key)/valor(value)
-# Hashes are denoted with curly braces:
+# Hashes são o principal dicionário de Ruby com pares de chaves(keys)/valor(value).
# Hashes são simbolizados com chaves "{}"
hash = {'color' => 'green', 'number' => 5}
hash = {'cor' => 'verde', 'numero' => 5}
hash.keys #=> ['cor', 'numero']
-# Hashes can be quickly looked up by key:
# Hashes podem ser rapidamente pesquisado pela chave (key)
hash['cor'] #=> 'verde'
hash['numero'] #=> 5
-# Asking a hash for a key that doesn't exist returns nil:
# Procurar em um hash por uma chave que não existe retorna nil:
hash['nothing here'] #=> nil
hash['nada aqui'] #=> nil
-# Iterate over hashes with the #each method:
# Interar sobre hashes com o método #each:
hash.each do |k, v|
puts "#{k} is #{v}"
@@ -226,7 +185,6 @@ hash.each do |k, v|
puts "#{k} é #{v}"
end
-# Since Ruby 1.9, there's a special syntax when using symbols as keys:
# Desde o Ruby 1.9, temos uma sintaxe especial quando usamos simbolos como chaves (keys)
new_hash = { defcon: 3, action: true}
@@ -235,12 +193,9 @@ novo_hash = { defcon: 3, acao: true}
new_hash.keys #=> [:defcon, :action]
novo_hash.keys #=> [:defcon, :acao]
-# Tip: Both Arrays and Hashes are Enumerable
# Dica: Tanto Arrays quanto Hashes são Enumerable
-# They share a lot of useful methods such as each, map, count, and more
# Eles compartilham um monte de métodos úteis como each, map, count e mais
-# Control structures
# Estruturas de controle
if true
@@ -272,11 +227,8 @@ end
#=> contador 4
#=> contador 5
-# HOWEVER
# PORÉM
-# No-one uses for loops
# Ninguém usa para loops
-# Use `each` instead, like this:
# Use "each" em vez, dessa forma:
(1..5).each do |counter|
@@ -343,19 +295,16 @@ else
puts "Alternative grading system, eh?"
end
-# Functions
# Funções
def dobrar(x)
x * 2
end
-# Functions (and all blocks) implcitly return the value of the last statement
# Funções (e todos os blocos) retornam implicitamente o valor da última linha
double(2) #=> 4
dobrar(2) #=> 4
-# Parentheses are optional where the result is unambiguous
# Parênteses são opicionais onde o resultado é claro
double 3 #=> 6
dobrar 3 #=> 6
@@ -371,7 +320,6 @@ def somar(x,y)
x + y
end
-# Method arguments are separated by a comma
# Argumentos de métodos são separados por uma virgula
sum 3, 4 #=> 7
somar 3, 4 #=> 7
@@ -379,9 +327,7 @@ somar 3, 4 #=> 7
somar somar(3,4), 5 #=> 12
# yield
-# All methods have an implicit, optional block parameter
# Todos os métodos possuem implicitamente um paramêntro opcional que é um bloco
-# it can be called with the 'yield' keyword
# ele pode ser chamado com a palavra chave 'yield'
def surround
@@ -406,7 +352,6 @@ ao_redor { puts 'Olá mundo' }
# }
-# Define a class with the class keyword
# Define uma classe com a palavra chave 'class'
class Human
@@ -480,7 +425,6 @@ class Humano
end
-# Instantiate a class
# Instaciando uma classe
jim = Human.new("Jim Halpert")
jim = Humano.new("Jim Halpert")
@@ -488,7 +432,6 @@ jim = Humano.new("Jim Halpert")
dwight = Human.new("Dwight K. Schrute")
dwight = Humano.new("Dwight K. Schrute")
-# Let's call a couple of methods
# Vamos chamar um par de métodos
jim.species #=> "H. sapiens"
jim.especies #=> "H. sapiens"
@@ -508,15 +451,12 @@ dwight.especies #=> "H. sapiens"
dwight.name #=> "Dwight K. Schrute"
dwight.nome #=> "Dwight K. Schrute"
-# Call the class method
# Chamar o método de classe
Human.say("Hi") #=> "Hi"
Humano.diz("Oi") #=> "Oi"
-# Class also is object in ruby. So class can have instance variables.
-# Uma classe também é objeto em Ruby. Então uma classe pode possuir um variavel de instancia
-# Class variable is shared among the class and all of its descendants.
-# Variavies de classe são compartilhadas entre a classe e todos os seus descendentes.
+# Uma classe também é objeto em Ruby. Então uma classe pode possuir variável de instância
+# Variáveis de classe são compartilhadas entre a classe e todos os seus descendentes.
# base class
class Human
@@ -559,8 +499,7 @@ Humano.foo = 2 # 2
Worker.foo # 2
Trabalhador.foo # 2
-# Class instance variable is not shared by the class's descendants.
-# Uma variavel de instancia não é compartilhada por suas classes decendentes.
+# Uma variável de instância não é compartilhada por suas classes decendentes.
class Human
@bar = 0