-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Becky Nisttahuz #157
base: main
Are you sure you want to change the base?
Becky Nisttahuz #157
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Exercises The Object Model | ||
1. How do we create an object in Ruby? Give an example of the creation of an object. | ||
|
||
class SmartAnimal | ||
class SmartAnimal | ||
end | ||
|
||
crow = SmartAnimal.new | ||
|
||
|
||
2. What is a module? What is its purpose? How do we use them with our classes? Create a module for the class you created in exercise 1 and include it properly. | ||
A module is a collection of reusable behaviors that can be use in other classes. We use them with our classes by using the include method. | ||
|
||
module Communicate | ||
end | ||
|
||
class SmartAnimal | ||
include Communicate | ||
end | ||
|
||
crow = SmartAnimal.new |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#Exercises: | ||
#1. Create a class called MyCar. | ||
|
||
class MyCar | ||
attr_accessor :color | ||
attr_reader :year | ||
|
||
def initialize(year, color, model) | ||
@year = year | ||
@color = color | ||
@model = model | ||
@speed = 0 | ||
end | ||
|
||
def speeds(number) | ||
@speed += number | ||
puts "Going too fast!" | ||
end | ||
|
||
def brakes(number) | ||
@speed -= number | ||
puts "Keep slowing down" | ||
end | ||
|
||
def speed | ||
puts "You are going #{@speed} miles per hour." | ||
end | ||
|
||
def shut_car_off | ||
@speed = 0 | ||
puts "Please turn the car off" | ||
end | ||
|
||
def spray_paint(color) | ||
self.color = color | ||
puts "New #{color} color for your car!" | ||
end | ||
end | ||
|
||
toyota = MyCar.new(1991, 'gray', 'camri') | ||
puts toyota.color | ||
toyota.spray_paint('black') | ||
puts toyota.color | ||
#toyota.speeds(80) | ||
#toyota.speed | ||
#toyota.brakes(70) | ||
#toyota.speed | ||
#toyota.shut_car_off | ||
#toyota.speed | ||
#toyota.color = 'green' | ||
#puts toyota.color | ||
#puts toyota.year | ||
|
||
|
||
#2. I added an accessor method to the MyCar class to change and view the color of your car.Then added an accessor method that allows me to view, but not modify, the year of the car. | ||
#3. I create a method called spray_paint that can be called on an object and will modify the color of the car. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,63 @@ | ||
# Create a person class with at least 2 attributes and 2 behaviors. | ||
# Create a person class with at least 2 attributes and 2 behaviors. | ||
# Call all person methods below the class and print results | ||
# to the terminal that show the methods in action. | ||
|
||
# YOUR CODE HERE | ||
|
||
class Person | ||
attr_reader :age, :weight, :cook, :work | ||
def initialize(age, weight) | ||
@age = age | ||
@weight = weight | ||
@cook = true | ||
@work = false | ||
end | ||
|
||
def have_birthday(older) | ||
@age += older | ||
puts "I am now #{age} years old" | ||
end | ||
|
||
def no_appetite(lost_weight) | ||
@weight -= lost_weight | ||
puts "I am never hungry so I lost some weight. Now I weight #{weight} pounds." | ||
end | ||
|
||
def cooks | ||
@cook = true | ||
puts "I love to cook #{cook}" | ||
end | ||
|
||
def works | ||
@work = false | ||
puts "I do currently work #{work}" | ||
end | ||
end | ||
|
||
ana = Person.new(21, 130) | ||
p ana.age | ||
p ana.weight | ||
p ana.cook | ||
p ana.work | ||
ana.have_birthday(10) | ||
ana.no_appetite(9) | ||
ana.cooks | ||
ana.works | ||
p ana.age | ||
p ana.weight | ||
p ana.cook | ||
p ana.work | ||
|
||
oliver = Person.new(40, 164) | ||
p oliver.age | ||
p oliver.weight | ||
p oliver.cook | ||
p oliver.work | ||
oliver.have_birthday(1) | ||
oliver.no_appetite(2) | ||
oliver.cooks | ||
oliver.works | ||
p oliver.age | ||
p oliver.weight | ||
p oliver.cook | ||
p oliver.work |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,87 @@ | ||
|
||
## Section 4 Reflection | ||
|
||
1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique? | ||
Time management is hard for me since I need to read not once, not twice but sometimes even three times the same information for me to be able to retain the information. I like the idea of having a timer to have a better flow with homework and learning in general. I just have to make sure I still learn what I need to to learn in that time sice I am learning while completing tasks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turing can and will provide accommodations for students whose first language is not English and need extra time. I encourage you to advocate for that with your Mod 1 instructors early in the module if you'd like to have that! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! I will make sure I do that. |
||
|
||
1. Regarding the work you did around setting intentions in Step 1 of the Pomodoro technique - how did that go? Were you surprised by anything (did you find yourself way more focused than you realized, more distracted that you thought you'd be, estimating times accurately or totally off, etc)? | ||
I was more distracted than expected. I think I just need more practice and getting use to idea of having a timer. I found that it added more pressure and I found myself not being able to focus very well. The more I tried it though, the better it got. | ||
|
||
1. In your own words, what is a Class? | ||
A Class is like a blueprint of an object. It defines its attributes and methods. | ||
|
||
1. What is an attribute of a Class? | ||
An attribute of a Class is a specific property of an object. Is the information the object holds. | ||
|
||
1. What is behavior of a Class? | ||
Behavior of a lass tells us how the Class will react. It is what an object is capable of doing. | ||
|
||
1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors: | ||
|
||
```rb | ||
|
||
class CuteDog | ||
attr_reader :name, :weight, :playful, :loud | ||
|
||
def initialize(name, weight) | ||
@name = name | ||
@weight = weight | ||
@playful = false | ||
@loud = true | ||
end | ||
|
||
def older | ||
@age += 10 | ||
puts "Simba is now #{age} old" | ||
end | ||
|
||
def bigger(weights_more) | ||
@weight += weights_more | ||
puts "The older he gets the bigger Simba gets. Last year he was weigthing #{weight} pounds" | ||
end | ||
|
||
def smaller(weights_less) | ||
@weight -= weights_less | ||
puts "After year 12, Simba started getting thiner, now he is #{weight} punds" | ||
end | ||
|
||
def barks | ||
@loud = true | ||
puts "Simba's bark is very loud #{loud}" | ||
end | ||
|
||
def plays | ||
@playful = false | ||
puts "Simba likes to play #{playful} " | ||
end | ||
end | ||
|
||
simba = CuteDog.new("Simba", 70) | ||
p simba.name | ||
p simba.weight | ||
p simba.playful | ||
p simba.loud | ||
simba.bigger(10) | ||
simba.smaller(19) | ||
simba.plays | ||
simba.barks | ||
p simba.name | ||
p simba.weight | ||
p simba.playful | ||
p simba.loud | ||
``` | ||
|
||
1. How do you create an instance of a class? | ||
By calling the 'new' method on the class. Then is stored in a variable. | ||
|
||
1. What questions do you still have about classes in Ruby? | ||
I do have many questions but I am hoping the more I practice the more I will understand the basic questions. I am still trying to understand for example if there are other types of classes in Ruby? | ||
|
||
- Have the time estimates matched up with your experience? | ||
I definitely spent more time than I was expecting. I am the kind of learner that has to re-read things and have to practice over and over to learn well. | ||
|
||
- When you sit down to start working, do you have a clear goal of what you want to accomplish and in how much time? If so, how aligned is that to what actually happens? | ||
I do have a clear goal I want to accomplish when working on something. With coding however since I am just starting to learn the basics, it takes me longer than expected. I believe the more comfortable I get with the basics, the more I will be able to follow my time limits and goals. | ||
|
||
1. What questions do you still have about classes in Ruby? | ||
- How do you work best - in 2 hour blocks, 4 hour blocks, etc? Do you take breaks regularly? Do you have a system to hold yourself accountable to taking breaks? | ||
I work best in smaller blocks of time. I do try to takes breaks as soon as start feeling I am not paying as much attention, or when I have to read over and over the same thing to understand it. I am actually looking for an alternative to a timer to take breaks. For now, I am using a timer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason you used
self
here??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we already have the attr_accessor :color.