Created
November 15, 2018 10:34
-
-
Save kbberker/75d7e163f670f8ddd71cf21703828980 to your computer and use it in GitHub Desktop.
Wizard Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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