def process_defn(exp)
type1 = exp[1].first
type2 = exp[2].first rescue nil
if type1 == :args and [:ivar, :attrset].include? type2 then
name = exp.shift
case type2
when :ivar then
exp.clear
return "attr_reader #{name.inspect}"
when :attrset then
exp.clear
return "attr_writer :#{name.to_s[0..-2]}"
else
raise "Unknown defn type: #{exp.inspect}"
end
end
comm = exp.comments
name = exp.shift
args = process exp.shift
args = "" if args == "()"
exp.shift if exp == s(s(:nil))
body = []
until exp.empty? do
body << indent(process(exp.shift))
end
body << indent("# do nothing") if body.empty?
body = body.join("\n")
return "#{comm}def #{name}#{args}\n#{body}\nend".gsub(/\n\s*\n+/, "\n")
end