Apartamento novo para venda – Vila Andrade – São Paulo/SP – (11) 99500-4519

Apartamento com vista total para o verde.

Edifício com excelente infra-estrutura (2 piscinas,  coberta e descoberta, quadra poliesportiva, churrasqueira e forno para pizza, academia, brinquedoteca e salão de festas

Sacada com churrasqueira.

Piso de porcelanato colocado em todo o apartamento.

Apartamento novinho, nunca habitado.

Edifício Luz, Condomínio Fotografia luz_2 luz_4 luz_5 luz_6 luz_7 luz_8 luz_9 SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC SONY DSC3 quartos(suítes)
2 vagas de garagem
Cozinha com abertura para a sacada

Apartamento de 3 suítes – novo – sacada com churrasqueira e vista para o verde

Ruby tips – returning a value of a hash

2.0.0-p247 :001 > board = {1=>’alexandre’, 2=>’beto’, 3=>’carlos’, 4=>’daniel’, 5=>’ernesto’}

2.0.0-p247 :014 > board.select{|_,v| v == “alexandre” }

=> {1=>”alexandre”}

So, if I only use the ‘select’ method, irb returns a hash.

If I only need the value, I must use the  ‘values’ method.

Then…

2.0.0-p247 :001 > board = {1=>’alexandre’, 2=>’beto’, 3=>’carlos’, 4=>’daniel’, 5=>’ernesto’}

2.0.0-p247 :018 > board.select{|_,v| v == “alexandre”}.values

=> ["alexandre"]

Ruby – Hash iterators

Creating a hash on irb….

2.0.0-p247 :001 > board = {1=>’alexandre’, 2=>’beto’, 3=>’carlos’, 4=>’daniel’, 5=>’ernesto’}

=> {1=>”alexandre”, 2=>”beto”, 3=>”carlos”, 4=>”daniel”, 5=>”ernesto”}

Now, iterating over it:

2.0.0-p247 :008 > board.each { |key, value| puts “#{key} #{value}” }

1 alexandre

2 beto

3 carlos

4 daniel

5 ernesto

=> {1=>”alexandre”, 2=>”beto”, 3=>”carlos”, 4=>”daniel”, 5=>”ernesto”}

Another iteration…adding a surname: 

2.0.0-p247 :012 > board.each { |key, value| puts “#{value} surname” }

alexandre surname

beto surname

carlos surname

daniel surname

ernesto surname

=> {1=>”alexandre”, 2=>”beto”, 3=>”carlos”, 4=>”daniel”, 5=>”ernesto”}

Ruby syntaxe

What’s the diference between ‘.each’ and ‘.each do’ ?

As I saw on  Codecademy (www.codecademy.com):

numbers = [1, 2, 3, 4, 5]
numbers.each { |element| puts element }

“Take this array (numbers) and for each element, print it to the console. As usual, we can use any placeholder name for the bit between two | | characters.”

 

Iteration 2-D array / array of arrays

s = [["ham", "swiss"], ["turkey", "cheddar"], ["roast beef", "gruyere"]]

s.each do |sub_array|
sub_array.each do |x|
puts x

end
end

 

key/value pairs

secret_identities = {
“The Batman” => “Bruce Wayne”,
“Superman” => “Clark Kent”,
“Wonder Woman” => “Diana Prince”,
“Freakazoid” => “Dexter Douglas”
}

secret_identities.each do |film, actor|
puts “#{film}: #{actor}”
end

 

Output:

The Batman: Bruce Wayne
Superman: Clark Kent
Wonder Woman: Diana Prince
Freakazoid: Dexter Douglas
{"The Batman"=>"Bruce Wayne", "Superman"=>"Clark Kent", "Wonder Woman"=>"Diana Prince", "Freakazoid"=>"Dexter Douglas"}

 

Iterating over a hash

lunch_order = {
“Ryan” => “wonton soup”,
“Eric” => “hamburger”,
“Jimmy” => “sandwich”,
“Sasha” => “salad”,
“Cole” => “taco”
}

lunch_order.each do |key, value|
puts value

end

OUTPUT:

wonton soup
hamburger
sandwich
salad
taco
{"Ryan"=>"wonton soup", "Eric"=>"hamburger", "Jimmy"=>"sandwich", "Sasha"=>"salad", "Cole"=>"taco"}

 

Seguir

Obtenha todo post novo entregue na sua caixa de entrada.