Skip to content

Instantly share code, notes, and snippets.

@alebaffa
Created March 12, 2014 16:21
Show Gist options
  • Save alebaffa/9510440 to your computer and use it in GitHub Desktop.
Save alebaffa/9510440 to your computer and use it in GitHub Desktop.
class Shape
def rotate
'Rotating around the center of ' + self.class.name
end
def play_sound
"I am playing the sound #{self.class.name}.aif"
end
end
class Amoeba < Shape
def rotate
'I am rotating around a end point!'
end
def play_sound
'I am playing the sound amoeba.hif'
end
end
Square = Class.new(Shape) # -> this should return an instance of Shape
#Square.rotate #-> so, I was expecting that calling rotate here would work. But instead it doesn't.
puts Square.new.rotate #-> I am forced to call Square.new everytime .... why?
puts Square.new.play_sound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment