- screenshots of scores will be posted in comments
- screenshots of completed sections will be posted in comments
I have not located instructions for how to have multiple folders open simultaneously in the VS Code environment.
I can open VS Code from the terminal by typing 'code'. I added that to the $Path.
.rb
I use cmd + B.
I use cmd + P.
- screenshots of your terminal after each exercise will be posted in comments
Day One Questions:
The command 'pwd' represents "print working directory" or "present working directory." This command, combined with 'ls', allows you to know your location within the file structure of your computer.
It prints the name of your local system. My terminal printed 'local'.
IRB
In order to start irb, I type 'irb' in the terminal prompt. To stop irb, I can type 'exit', 'quit', or 'CTRL + d'.
I can use irb for calcuations or to experiment with very short scripts.
Variables
I can create a variable by declaring a variable name equal to some information, such as: a = 13, b = "string", c4 = "explosive".
I found that numbers can appear in any position of a variable name except for the first character. Underscores may be used in variable names while hypens may not. Additionally, I didn't not find a way for a variable to be only a number for its name.
I can change the value by re-declaring it in irb.
Datatypes
I can determine the class of a variable by executing variable.class or "variable".class
reverse and upcase! (apparently different from upcase, sans exclamation)
I can convert an integer to a string by calling the .to_s method on the variable. For example, if I have the variable sand = 555, I can convert this from an integer to a string by executing sand.to_s, the output of which is "555".
Strings
If I have a string using the #{} interpolater, I would use double quotes for it to work.
The #{} is a string interpolater and substitutes any valid statement into the string. I could place another string, a variable name, a math expression, etc. and all would be substituded in to the string.
I would remove all vowels from a test string by execuding: test_string.delete('aeiou')
Input & Output
'puts' returns nil and outputs the variable/string after 'puts' while in irb. 'print' does the same thing as 'puts' but without a newline after.
'gets' takes information from the user. This information can be set equal to a variable name, can be converted to a different datatype, and can have methods called on it.
* Add a screenshot in the comments of the program you created that uses 'puts' and 'gets', and give it the title, "I/O".
Numbers & Arithmetic
Integers are whole numbers without a decimal point while floats are decimal numbers.
* Complete the challenge, and post a screenshot of your program in the comments with the title, "Numbers".
Booleans
- == is equal
-
= greater than or equal
- <= less than or equal
- != not equal
- && and
- || or
.empty? .nil? .end_with('')?
Conditionals
Flow control is built in paths for data in the program to take. There are options within if-elsif-else statements that execute when certain conditions are met.
This should print "Not many apples..." to the terminal.
apple_count = 4
if apple_count > 5
puts "Lots of apples!"
else
puts 'Not many apples...'
end
An infinite loop is a loop set to continue iterating until a prescribed condition is set for it to stop. As long as that condition is not met, the loop will continue infinitely. You can get out of an infinite loop by meeting the condition for it to terminate or typing ctrl + C.
* Take a screenshot of your program and terminal showing two different outputs, and post it in the comments with the title, "Conditionals".
nil
nil is its own class and also represents "nothing." We can use it set aside memory for a variable even if we don't have the data we need for it quite yet.
* Take a screenshot of your terminal after working through Step 4, and post it in the comments with the title, "nil".
Symbols
The use of symbols is beneficial in Ruby for effecient memory usage because it allows the program to reference the same object without making copies.
I believe so. I couldn't find an example where they did not apply.
* Take a screenshot of your terminal after working through Step 4, and post it in the comments with the title, "Symbols".
Arrays
In order to determine the number of elements in an array example, I could execute example.length.
Pizza is in the 0th slot.
Push adds an element to an existing array while pop removes and returns the element with the highest index.
Hashes
Arrays are ways to group values together while hashes assign a key that correspond to a value. One could create an array of hashes. Hashes remind me of a dictionary in that they have a key/word that is assigned to a value/definition or usage.
I would prefer an array for listing or grouping similar items while I would prefer a hash for completing profiles or forms. Let's say I had a room full of people that I wanted to collect data on. I would prefer an array to list all of the cities people are from, and I would prefer a hash to create a profile of information for each person. The profile could store their height, eye color, city of origin, occupation, and other keys.
* Take a screenshot of your terminal after working through Step 2, and post it in the comments with the title, "Hashes".
(Note: You will most likely only get to the following sections if you have more than a week for your pre-work. If you are doing the one week pre-work schedule, you may delete this section of the Gist.)
commented below
commented below
In order to call a function, I can take function(args). To store the result as a variable I can declare a variable as var = function(args).
* Describe the purpose of the following in Ruby classes: initialize method, new method, instance variables.
The purpose of the initialize method is to define the characteristics of the class object. It performs the setup of the object. The .new method specifies an instance of that object. I could be very wrong, but I think of the code block under class describing a template for an object and then the .new method creates a specific object with the template. The instance variables create a specific instance of that object. For example, I could have a class Square and define the instance variable to be the side length of the square. We could then define the methods area and perimeter to tell us the area and perimeter of the square, both of which are dependent upon the instance variable, the side length.
* How to Write a Program: Screenhero with your student mentor and share your program. Write a bit about what you found most challenging, and most enjoyable, in creating your program.
-
There are so many ways to complete a task successfully yet some solutions are more elegant than others. I found that especially with iterators and loops, there were almost too may options for me to construct a solution. Oftentimes, I couldn't see which solution would be the simplest until looking at the provided solution from the book writer. I think the only way for me to improve is to work through a high volume of exercises involving loops/iterators/do-end blocks.
-
The right method at the right time makes things a lot easier. When working with hashes and arrays, I found that knowing about available methods and perusing the Ruby documentation was really helpful. I found the number of methods intimidating, but I'm hoping that with some pointed exercises I'll get more exposure and increase my comfort level.
-
Notation is really important. I thankfully didn't have many times where I was missing a ( , [, or {, but I am struggling to memorize the notation for different blocks of code. I think I need more practice until its ingrained into my mind.
- git status is really helpful for me to understand where in the process of staging/committing I am.
- I don't feel confident at all with git. I'm going to try to do the rest of the CodeSchool git course to see more context.
If I'm working on a project with multiple people and we all merge our branches to the master, how do I resolve conflicts within our code?
* Describe your thinking on effective workflow. What shortcuts do you think you'll find most useful? What would you like to learn or practice that will most help you improve your speed and workflow?
As you complete each section, respond to the related questions below (mostly taken directly from the tutorial exercises):
Task F I/O