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"}

 

KIller apps for productivity

I decided to be a more focused guy and consequently a more productive since last year. I found and used a lot of apps

Here is the golden list of apps that helped me (I use all of them daily):

- Evernote

-Wunderlist

- Dropbox

- Google Drive / Google Docs

- Mailbox

 -Unroll me

- LastPass

- Rescue Time

They’re not in order of preference or functionalities…I just begin writing..

For sure there is always somebody missing and as soon as I remember i will post.

All of them can be used on desktops (macs/pcs), iphones and android.

For smartphones there is another list that I use at my android device. You should use a different ROM, not the stock one that usually sucks.

Since Nvember i am using the famous CYANOGEM MOD ones and it’s fantastic. At overall the android become faster and more stable.

At december I got an AVIATE invite and started using. It solves a huge problem in android devices: the mess!

Aviates clusters your apps by genre and by alphabetic list. So it becomes easier to find something and the UX is awesome.

Does anyone has an app to recommend?

KIller apps for productivity

I decided to be a more focused guy and consequently a more productive since last year. I found and used a lot of apps

Here is the golden list of apps that helped me (I use all of them daily basis):

- Evernote

-Wunderlist

- Dropbox

- Google Drive / Google Docs

- Mailbox

 -Unroll me

- LastPass

- Rescue Time

They’re not in order of preference or functionalities…I just begin writing..

For sure there is always somebody missing and as soon as I remember i will post.

All of them can be used on desktops (macs/pcs), iphones and android.

For smartphones there is another list that I use at my android device. You should use a different ROM, not the stock one that usually sucks.

Since November i am using the famous CYANOGEM MOD ones and it’s fantastic. At overall the android become faster and more stable.

At december I got an AVIATE invite and started using. It solves a huge problem in android devices: the mess!

Aviates clusters your apps by genre and by alphabetic list. So it becomes easier to find something and the UX is awesome.

Does anyone has an app to recommend?

Seguir

Obtenha todo post novo entregue na sua caixa de entrada.