March 29, 2024
flatiron school

My Journey Of Learning Programming Through Flatiron School #4

My name is Mason Ellwood and I’m currently working on Flatiron School’s Online Full Stack Web Development Program. Each week, I’ll be writing about my experience, what I’m learning, and tips on learning to code.

In the last post, I covered the definitions of a failing test and what data types Ruby, super fun stuff! Now that everything had a definition applied to it we are ready to get into arrays and interpolation! Heck yeah!

Arrays are used to store data as a collection. They do this by declaring literals or variable names separated by commas and wrapped in square brackets

 

Ex: this_is_an_array = [ “slot-one”, “slot-two”, “slot-three”, “slot-four”, “slot-five”, “slot-six”]

 

Remember!

*A class is a kind of like a template for creating objects in Ruby.

*A bundle is simply a bundle of information and behaviors.

*And a string is an object

Within your array, each element within your array is associated with a number that represents their order, this is called an index and they begin their index at 0.

 

Ex: this_is_an_array = [ “slot-one”, “slot-two”, “slot-three”, “slot-four”, “slot-five”, “slot-six”]

 

In order to call an element in the array you just created you must call the name of the array the number in which you want to call.

 

Ex: this_is_an_array[0] => “slot-one”

 

To assign a new value to a current index of that array, you can call the array index of the number you want to re-assign and define it to a new variable.

 

 

Or you can place, put, or take away whatever you want anywhere within this array. You can do this with a variety of different methods. I will not be covering every instance that was covered in the lesson, but for an example you can use the shovel method which employs the shovel operator ( << ) which allows you to add items at the end of the array. Similar to the shovel method you can also use #push method to do the same thing.

 

 

Moving forward I am finally ready to cover methods. Basically with arrays and methods you can do just about anything in Ruby and are the staple of the language. So what is a method…. It defines something new your program can do. They teach your Ruby program about a new routine or behavior it can use. This is an incredible tool because to my understanding they are the meat of your program and allow the practice of DRY or don’t repeat yourself logic. By defining your method once you can then call the method as many times as you would like.

 

 

The code above may seem dumb…. But if i encapsulate the repetitive strings within a method I do not need to repeat myself over and over again, remember to work towards  DRY haha. So the above method I wrote def a_bunch_of_strings is the method signature, which defines the basic properties of the method including the name of the method which is a_bunch_of_strings. Everything inside of this is considered the body, and remember this must in end. Once a method is defined you can call is as many times as you would like by using the method name. Then through string interpolation we can then make it dynamic (to check out more on string interpolation please check out this link: https://docs.ruby-lang.org/en/2.0.0/syntax/literals_rdoc.html)

 

 

Up until this point, I have not had any real issues with the Flatiron Schools, in fact it has been really enjoyable. This next post I may jump ahead quite a bit, so bear with me. But everyone I have met within the school has been great. What I really like is that once I finally do reach out to customer support with questions about the current course work, they don’t just belatedly tell you what the solution is, which is great. They allow me to work through it myself while they nudge me in the right direction. This can get kind of confusing though because you are communication over instant messenger. Which can be difficult when trying to work through which piece of your code does not work.

Leave a Reply

Your email address will not be published. Required fields are marked *