First few exercises in Ruby Monk
After doing Codeacademy and Chris Pine’s Learn to Program, there’s a lot of repetition for me with Ruby Monk, but also a lot of small details I’m glad to know and hope I can remember:
Do remember that placeholders aren’t just variables. Any valid block of Ruby code you place inside #{} will be evaluated and inserted at that location. Isn’t that very neat?
….
We’ve been using double quotes in all our string interpolation examples. A String literal created with single quotes does not support interpolation.
The essential difference between using single or double quotes is that double quotes allow for escape sequences while single quotes do not. What you saw above is one such example. “\n” is interpreted as a new line and appears as a new line when rendered to the user, whereas '\n' displays the actual escape sequence to the user.
-Ruby Monk
Who knew the difference between single and double quotes, or the idea that string interpolation could be use more than variables?! Obviously people who understand Ruby I suspect :)
Or how about this!
In Ruby, ? and : can be used to mean “then” and “else” respectively.
Oh snap! Not sure I will ever use it, but good to know. I also now know why we we used gsub in Codecademy and not sub, which is cool. I hate using random bits of code without knowing where their names come from. And it was great to review RegExp again, since I was feeling pretty fuzzy on that.
Something I like about Ruby Monk is that it doesn’t give you all the answers right away. It forces you to guess what method might exist to solve a problem “given the intuitiveness of the code”, which is pretty cool. I suspect that relying on what you think might work and testing it out is a pretty big deal in actual programing, rather than the way these other tutorials have gone which is to tell you ok here is a method, this is what it does, now retype what I have already told you to do.
While Learn to Program made me feel like “I get this, I totally get this” Ruby Monk is raising a lot of questions for me with the same material, which is probably a good thing. Some of the questions I feel like I should know the answer to already, while others I think I’ll learn later down the line and shouldn’t worry about it. Not sure if it is Ruby Monk or just me causing all this existential angst:
Method Syntax
Some methods seem to work like this:
variable.method(arguments)
but in Ruby Monk it seems like they are doing away with the parentheses
variable.method arguments
of course other methods use blocks, but that seems to make more sense to me.
are the paren optional?
APIs
I used APIs during my time with Thinkful. But I think I’m still a little vague as to what they are really or how to visualize them. For example when I used Instagram’s API to make a website that shows pictures of dogs wearing hats, I thought of APIs as a way for another website to share their data with you via the internet without you hosting all of that data yourself or seeing the inner workings of their server so that you can access secure data. Now I see in Ruby Monk that we are referring to the Ruby API and that it is what allows us to use methods. Does this work similar to instagram’s api? How can I use Ruby without the internet? Also is it a typo or intentional when they use the # here, I’ve seen it a few times:
The method the Ruby String API provides for this is String#split.
Memory Utilization
I haven’t really been thinking about this concept at all yet. I’m curious how this comes up, and how to write better code for when it does. Ruby Monk sort of throws it out there as something to think about, and now…well I’m thinking about it, without knowing much about it besides uh…memory…don’t use too much of it?
In the first case of using ‘+’, the original string is not modified, as a third string ‘RubyMonk’ is created. This can make a huge difference in your memory utilization, if you are doing really large scale string manipulations.
Well that’s probably enough internet babble for one day

















