Я очень новичок в Ruby.
При использовании хэшей в качестве переменных экземпляра это
class Hero
def initialize (stats={})
Или
class Hero
def initialize (stats={'Atk':0, 'Def':0})
Или
class Hero
def initialize (stats)
Или как-то лучше? Я получаю около 30 ошибок в строке инициализации из-за неожиданного ':' и т. Д.
Вероятно, в строке инициализации имеется 10 хэшей. Лучше вместо этого иметь индивидуальную переменную для каждого состояния? Заранее спасибо!
Извините, если это дубликат, но я не видел никаких вопросов по этому поводу.
Мой класс:
class Hero
attr_accessor :nam, :desc, :race, :clas, :bg, :heroLVL, :hitpoints, :armC, :spd, :sdcwic, :modifiers, :proficiencies, :skills, :languages, :inventory, :equipment, :coins, :features, :feats, :spellsKnown, :spellSlots, :maxSpellSlots, :currentSpellSlots, :cantrips
def initialize(nam, desc = {}, race, clas = [], bg, heroLVL = {}, hitpoints = {'Current HP' : 0, 'Max HP' : 0, 'Temp HP' : 0}, armC, spd, sdcwic = {'Stre' : 0, 'Dex' : 0, 'Con' : 0, 'Wis' : 0, 'Int' : 0, 'Cha' : 0}, modifiers = {'Stre' : 0, 'Dex' : 0, 'Con' : 0, 'Wis' : 0, 'Int' : 0, 'Cha' : 0, 'Proficiency' : 0}, proficiencies = [], skills = {}, languages = [], inventory = {}, equipment = {}, coins = {'Copper' : 0, 'Silver' : 0, 'Electrum' : 0, 'Gold' : 0, 'Platinum' : 0}, features = [], feats = [], spellsKnown = [], spellSlots = {}, maxSpellSlots = {}, currentSpellSlots = {}, cantrips = [])
#description
@nam = nam
@desc = desc
#stats
@race = race
@clas = clas
@bg = bg
@heroLVL = heroLVL
@hitpoints = hitpoints
@armC = armC
@spd = spd
#modifiers
@sdcwic = sdcwic
@modifiers = modifiers
@proficiencies = proficiencies
@skills = skills
@languages = languages
#inventory
@inventory = inventory
@equipment = equipment
@coins = coins
#features
@features = features
@feats = feats
#casting
@spellsKnown = spellsKnown
@spellSlots = spellSlots
@maxSpellSlots = maxSpellSlots
@currentSpellSlots = currentSpellSlots
@cantrips = cantrips
end
end