Skip to content

Instantly share code, notes, and snippets.

@kbberker
Created November 15, 2018 10:34
Show Gist options
  • Save kbberker/75d7e163f670f8ddd71cf21703828980 to your computer and use it in GitHub Desktop.
Save kbberker/75d7e163f670f8ddd71cf21703828980 to your computer and use it in GitHub Desktop.
Wizard Class
class Wizard
attr_accessor :name, :age, :hair_colour, :favourite_spell
@@all = []
def initialize(name, age, hair_colour, favourite_spell)
@name = name
@age = age
@hair_colour = hair_colour
@favourite_spell = favourite_spell
@@all << self
end
def cast_spell
"#{@favourite_spell}!!!!"
end
def self.all
@@all
end
end
harry = Wizard.new("Harry Potter", 12, "brown", "Expecto Patronum")
# => <Wizard:0x00007f97ff16b658 @name="Harry Potter", @age=12, @hair_colour="brown", @favourite_spell="Expecto Patronum">
harry.cast_spell
# => "Expecto Patronum!!!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment