Skip to content
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

Tyler Ross #154

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions section4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ When you are all done with the lessons, exercises, and questions for today, you

1. Work through the following lessons. Any files that you create while working can be kept in today's `exercises` directory.

- [ ] [What Are Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#whatareobjects) section from LaunchSchool.
- [x] [What Are Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#whatareobjects) section from LaunchSchool.

- [ ] [Classes Define Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#classesdefineobjects) section from LaunchSchool.
- [x] [Classes Define Objects](https://launchschool.com/books/oo_ruby/read/the_object_model#classesdefineobjects) section from LaunchSchool.

- [ ] [Classes and Objects Part 1](https://launchschool.com/books/oo_ruby/read/classes_and_objects_part1) from LaunchSchool.
- [x] [Classes and Objects Part 1](https://launchschool.com/books/oo_ruby/read/classes_and_objects_part1) from LaunchSchool.

- [ ] [Objects, Attributes and Methods](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#11.-objects,-attributes,-and-methods) from Ruby in 100 Minutes.
- [x] [Objects, Attributes and Methods](http://tutorials.jumpstartlab.com/projects/ruby_in_100_minutes.html#11.-objects,-attributes,-and-methods) from Ruby in 100 Minutes.

1. Work through the files in the section4/exercises directory.

Expand Down
23 changes: 22 additions & 1 deletion section4/exercises/burrito.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Add the following methods to this burrito class and
# Add the following methods to this burrito class and
# call the methods below the class:
# 1. add_topping
# 2. remove_topping
Expand All @@ -11,9 +11,30 @@ def initialize(protein, base, toppings)
@base = base
@toppings = toppings
end

def add_topping(topping)
toppings.push topping
end

def remove_topping
toppings.shift()
end

def change_protein(protein)
@protein = protein
end
end

dinner = Burrito.new("Beans", "Rice", ["cheese", "salsa", "guacamole"])
p dinner.protein
p dinner.base
p dinner.toppings

dinner.add_topping("cilantro")
p dinner.toppings

dinner.remove_topping
p dinner.toppings

dinner.change_protein("Chorizo")
p dinner.protein
9 changes: 8 additions & 1 deletion section4/exercises/dog.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# In the dog class below, write a `play` method that makes
# the dog hungry. Call that method below the class, and
# the dog hungry. Call that method below the class, and
# print the dog's hunger status.

class Dog
Expand All @@ -19,6 +19,11 @@ def bark
def eat
@hungry = false
end

def play
@hungry = true
end

end

fido = Dog.new("Bernese", "Fido", 4)
Expand All @@ -28,3 +33,5 @@ def eat
p fido.hungry
fido.eat
p fido.hungry
fido.play
p fido.hungry
3 changes: 3 additions & 0 deletions section4/exercises/ex1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"hello".class

"world".class
45 changes: 45 additions & 0 deletions section4/exercises/ex2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class GoodDog
end

sparky = GoodDog.new


module Speak
def speak(sound)
puts sound
end
end

class GoodDog
include Speak
end

class HumanBeing
include Speak
end

sparky = GoodDog.new
sparky.speak("Arf!")
bob = HumanBeing.new
bob.speak("Hello!")


module Speak
def speak(sound)
puts "#{sound}"
end
end

class GoodDog
include Speak
end

class HumanBeing
include Speak
end

puts "---GoodDog ancestors---"
puts GoodDog.ancestors
puts ''
puts "---HumanBeing ancestors---"
puts HumanBeing.ancestors
32 changes: 32 additions & 0 deletions section4/exercises/ex3-2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class GoodDog
attr_accessor :name, :height, :weight

def initialize(n, h, w)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll generally want to avoid using single letter variables in Ruby and most modern languages. The reason is readability for other devs, and it's simply not convention. In this case, I totally see where they came from and it makes sense enough, but definitely not a habit you want to get into.

@name = n
@height = h
@weight = w
end

def speak
"#{name} says arf!"
end

def change_info(n, h, w)
self.name = n
self.height = h
self.weight = w
end

def info
"#{self.name} weighs #{self.weight} and is #{self.height} tall."
end
end


sparky = GoodDog.new('Sparky', '12 inches', '10 lbs')
puts sparky.info

sparky.change_info('Spartacus', '24 inches', '45 lbs')
puts sparky.info

puts sparky.weight
33 changes: 33 additions & 0 deletions section4/exercises/ex3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class GoodDog
def initialize(name)
@name = name
end

def speak
"#{@name} says arf!"
end

def name
@name
end

def name=(name)
@name = name
end

end

sparky = GoodDog.new("Sparky")
puts sparky.speak
puts sparky.name
sparky.name = "Spartacus"
puts sparky.name


fido = GoodDog.new("Fido")
puts fido.speak




#Want to keep this example, continuing example on ex3-2.rb
17 changes: 17 additions & 0 deletions section4/exercises/ex4.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Student
attr_accessor :first_name, :last_name, :primary_phone_number

def introduction(target)
puts "Hi #{target}, I'm #{first_name}!"
end

def favorite_number
7
end

end

frank = Student.new
frank.first_name = "Frank"
frank.introduction('Katrina')
puts "Frank's favorite number is #{frank.favorite_number}."
33 changes: 31 additions & 2 deletions section4/exercises/person.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# 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
def initialize (name, age, healthy)
@name = name
@age = age
@healthy = healthy
end

def birthday
@age += 1
end

def age
@age
end

def poisoned
@healthy = false
end

def healthy
@healthy
end
end

tyler = Person.new("Tyler", 31, true)
p tyler
tyler.birthday
puts tyler.age
tyler.poisoned
puts tyler.healthy
21 changes: 20 additions & 1 deletion section4/reflection.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
## Section 4 Reflection

1. How different did your workflow feel this week, considering we asked you to follow the Pomodoro technique?
It felt better in some respects, worse in others. 25 minutes is too small a time for me, as it can take me a while to figure out where I left off.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good reflection! Totally ok to "up" that time to something that feels better for you. (BTW I am the same - set my timer for 50 then take a little longer of a break)


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)?
Setting intentions was effective. The intention was usually a very small task due to the time limit, and made it easy to focus on and track progress.

1. In your own words, what is a Class?
A class is a set of common qualities.

1. What is an attribute of a Class?
An attribute is a piece of data belonging to a class.

1. What is behavior of a Class?
A behavior is an action taken by or done to a class.

1. In the space below, create a Dog class with at least 2 attributes and 2 behaviors:

```rb
class Dinner
def initialize (food, beverage)
@food = food
@beverage = beverage
end

def eat_food
@food = false
end

def drink_beverage
@beverage = false
end
end

```

1. How do you create an instance of a class?
`name_of_object = Class.new(attributes)`

1. What questions do you still have about classes in Ruby?
1. What questions do you still have about classes in Ruby?