Skip to content

Instantly share code, notes, and snippets.

@jetaggart
Last active December 17, 2015 00:29
Show Gist options
  • Select an option

  • Save jetaggart/5521408 to your computer and use it in GitHub Desktop.

Select an option

Save jetaggart/5521408 to your computer and use it in GitHub Desktop.
class Dog
@@all_dogs = []
def initialize(name)
@@all_dogs << self
@name = name
end
def self.bark
@@all_dogs.each {|dog| dog.bark }
end
def bark
puts "#{@name}: Bark!"
end
end
harleigh = Dog.new('har har')
mala = Dog.new('mala')
mala.bark # mala: Bark!
harleigh.bark # har har: Bark!
Dog.bark # mala: Bark!, har har: Bark!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment