Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/maruku/structures.rb

Instance Method Summary collapse

Instance Method Details

#safe_attr_accessor(symbol, klass) ⇒ Object



41
42
43
# File 'lib/maruku/structures.rb', line 41

def safe_attr_accessor(symbol, klass)
	attr_accessor symbol
end

#safe_attr_accessor2(symbol, klass) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/maruku/structures.rb', line 24

def safe_attr_accessor2(symbol, klass)
attr_reader symbol
code = <<-EOF
def #{symbol}=(val)  
	if not val.kind_of? #{klass}
		s = "Could not assign an object of type \#{val.class} to #{symbol}.\n"
		s += "Tried to assign\n\#{val.inspect}\nto #{symbol} of object\n"
		s += "\#{self.inspect}"
		raise s
	end
	@#{symbol} = val
end

EOF
module_eval code
end