Skip to content

Instantly share code, notes, and snippets.

@benbagley
Last active October 31, 2017 17:55
Show Gist options
  • Save benbagley/9868755723709f7e867b to your computer and use it in GitHub Desktop.
Save benbagley/9868755723709f7e867b to your computer and use it in GitHub Desktop.
class Cat
attr_reader :color, :breed, :name
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
def feed(food)
puts "Mmmm, " + food + "!"
@hungry = false
end
def hungry?
if @hungry
puts "I'm hungry!"
else
puts "I'm full!"
end
@hungry
end
def speak
puts "Meow!"
end
end
kitty = Cat.new("grey", "Persian")
puts "What color is our cat?"
puts kitty.color
puts "Let's give our new cat a name"
kitty.name = "Betsy"
puts kitty.name
puts "Is our cat hungry now?"
kitty.hungry?
puts "Let's feed our cat"
kitty.feed("tuna")
puts "Is our cat hungry now?"
kitty.hungry?
puts "Our cat can make noise"
kitty.speak
def fav_foods
food_array = []
3.times do
puts "Name of favorite foods."
food_array << gets.chomp
end
puts "Your favorite foods are #{food_array.join(", ")}."
food_array.each do |food|
puts "I like #{food} too!"
end
p food_array
end
fav_foods
def greeting
puts "Ben Clarke:"
name = gets.chomp
puts "Hello" + " " + name
end
# Was cat.rb
class Pet
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed)
@color = color
@breed = breed
@hungry = true
end
def feed(food)
puts "Mmmm, " + food + "!"
@hungry = false
end
def hungry?
if @hungry
puts "I'm hungry!"
else
puts "I'm full!"
end
@hungry
end
end
class Cat < Pet
def speak
puts "Meow!"
end
end
puts "Our cat can make noise"
kitty.speak
class Dog < Pet
def speak
puts ":Woof!"
end
end
puppy = Dog.new("Brown", "Bulldog")
puppy.speak
puts puppy.breed
# puts "Let's inspect our new cat:"
# puts kitty.inspect
# puts "What class does our new cat belong to?"
# puts kitty.class
# puts "Is our new cat an object?"
# puts kitty.is_a?(Object)
if (5+5==10)
puts "this is true"
else
puts "this is false"
end
def choose
puts "Do you like programming? Yes, no, or maybe please."
choice = gets.chomp
case choice.downcase
when "yes"
puts "That\'s great!"
when "no"
puts "That\'s too bad!"
when "maybe"
puts "Glad you are giving it a chance!"
else
puts "I have no idea what that means."
end
end
# 3.times do
# puts "Hello!"
# end
# number = 0
# while (number <= 10) do # while this condition is true, do...
# p "the number is now #{number}" # whatever is in this code block
# number += 1 # short for number = number + 1
# end # don’t forget your end
(0..10).each do |n|
p "the new number is #{n}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment