Change [in coding] can be scary!
You spend months or even years learning a coding discipline. Then suddenly you have to start all over in an entirely different language. Sure they have their share of overlapping but sometimes that makes things harder instead of easier.
Going from JavaScript to Ruby hasn’t been unbearable thus far but still is giving some tricks. I only have started with the basics but so far some interesting differences I have run into are with #times and #each.
#times is a method in the integer class. It takes in an integer and iterates over the block that amount of times. Simple example:
10.times do |i|
puts "i is: #{i}"
end
The i is the block parameter. It is placed within the pipes. This code will print out “i is [whatever iteration number the code is on] i.e.:
“i is 0”
“i is 1”
“i is 2” … until it reaches “i is 9” as 0,9 would be ten times.
#each can take a range instead of just an integer. Simple example:
(1..20).each do |num|
puts num
end
This will take the numbers from 1 until 20 and plug them into the num variable. The code has the num variable printed so this will simply just count from 1 to 20. #each can take many different data types but at this point in the learning a range is what I am familiar with.