# File lib/maruku/structures.rb, line 24 def safe_attr_accessor1(symbol, klass) attr_reader symbol code = <<-EOF def #{symbol}=(val) if not val.kind_of? #{klass} s = "\nCould not assign an object of type \#{val.class} to #{symbol}.\n\n" s += "Tried to assign object of class \#{val.class}:\n"+ "\#{val.inspect}\n"+ "to \#{self.class}::#{symbol} constrained to be of class #{klass}.\n" raise s end @#{symbol} = val end EOF module_eval code end
# File lib/maruku/structures.rb, line 42 def safe_attr_accessor2(symbol, klass) attr_accessor symbol end