Sha256: 95d0c9ca20cc0c981aebfe15141f5603acebf3189f594f7ec636abf7d2073296
Contents?: true
Size: 421 Bytes
Versions: 20
Compression:
Stored size: 421 Bytes
Contents
class Module # Like attr_writer, but the writer method validates the # setting against the given block. def attr_validator(*symbols, &validator) symbols.each do |symbol| define_method "#{symbol}=" do |val| unless validator.call(val) raise ArgumentError, "Invalid value provided for #{symbol}" end instance_variable_set("@#{symbol}", val) end end end end
Version data entries
20 entries across 20 versions & 1 rubygems