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 = "def \#{symbol}=(val)\nif not val.kind_of? \#{klass}\ns = \"Could not assign an object of type \\\#{val.class} to \#{symbol}.\\n\"\ns += \"Tried to assign\\n\\\#{val.inspect}\\nto \#{symbol} of object\\n\"\ns += \"\\\#{self.inspect}\"\nraise s\nend\n@\#{symbol} = val\nend\n\n"
module_eval code
end