Class: Module

Inherits:
Object show all
Defined in:
lib/amp-front/third_party/maruku/structures.rb

Instance Method Summary collapse

Instance Method Details

#safe_attr_accessor1(symbol, klass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/amp-front/third_party/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

#safe_attr_accessor2(symbol, klass) ⇒ Object Also known as: safe_attr_accessor



42
43
44
# File 'lib/amp-front/third_party/maruku/structures.rb', line 42

def safe_attr_accessor2(symbol, klass)
	attr_accessor symbol
end