On day four we really got into Ruby. Most of the day was spent in lectures with a few labs mixed in and was punctuated by most of us being at the campus pretty late working on our homework.
A few takeaways that I need to make sure get ingrained in my head…
A method always returns the return of the last command it executes. This means if you write a method to manipulate an array and want to call that method later and have it return the manipulated array that you need to call the name of the array at the end of the method in order for the method itself to return that array.
Puts ALWAYS returns nil. So try really hard not to actually put it in a method. Definitely make sure that its not the last thing in an array unless I want the array to return nil.
I also saw syntax I like for short if statements to keep them more compact.
if x == 1 puts “x is 1!” end
is equivalent to
puts “x is 1!” if x == 1
I think the second iteration of code looks much cleaner and would like to start thinking of short if statements that way before I put them in a block.