Ruby - Setter methods for hash properties
问题 I've been tooling around with Ruby by converting a pen and paper RPG to a script. Right now I have a character's stats kept in a hash, which I would like to be able to set via public method. I got that working with: class Character attr_reader :str, :con, :dex, :wis, :int, :level, :mods, :stats def initialize str, con, dex, wis, int, cha, level = 1 @stats = { :str => str, :con => con, :dex => dex, :wis => wis, :int => int, :cha => cha } @mods = {} @level = level @stats.each_pair do |key,