Skip to content

Instantly share code, notes, and snippets.

@nelantone
Created July 26, 2016 20:09
Show Gist options
  • Save nelantone/293d91bfb73b020ae371ad5efd207ec9 to your computer and use it in GitHub Desktop.
Save nelantone/293d91bfb73b020ae371ad5efd207ec9 to your computer and use it in GitHub Desktop.
3.5
str = "hello"
str.is_a?(Object)
str.class
class String
def star
self + " *"
end
end
str.star
"yay".star
class String
def self.announce
puts "I am the String class"
end
end
String.announce
#{}"hello".announce
puts '#######'
class Pet
attr_reader :color, :breed
attr_accessor :name
def initialize(color, breed, hungry)
@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
class Dog < Pet
def speak
puts "Woof!"
end
end
Kitty = Cat.new('grey', 'what?','')
puts "Let's inspect our new cat:"
puts Kitty.inspect
puts "What class our new cat beling to?"
puts Kitty.class
puts "It's our new cat an object?"
puts Kitty.is_a?(Object)
puts "What color it's our cat?"
puts Kitty.color
puts "Let's give our new cat a name"
Kitty.name = "Fufu"
puts Kitty.name
puts "Is our cat hungry now?"
Kitty.hungry?
puts "Let's feed our cat"
Kitty.feed("Wiskas")
puts "It is our cat hungry now?"
Kitty.hungry?
puts "Our cat can make noise"
puts Kitty.speak
uika = Dog.new("grey", "Weimaraner", true)
uika.speak
puts uika.breed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment