From f705f0fce151863091ad77753105f0d15270edec Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 10 Apr 2014 20:34:29 -0500 Subject: Ruby: step0, step1 --- ruby/printer.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ruby/printer.rb (limited to 'ruby/printer.rb') diff --git a/ruby/printer.rb b/ruby/printer.rb new file mode 100644 index 0000000..2d46e07 --- /dev/null +++ b/ruby/printer.rb @@ -0,0 +1,23 @@ +require "types" + +def _pr_str(obj, print_readably=true) + _r = print_readably + return case obj + when List + "(" + obj.map{|x| _pr_str(x, _r)}.join(" ") + ")" + when Vector + "[" + obj.map{|x| _pr_str(x, _r)}.join(" ") + "]" + when String + if _r + "\"" + obj.gsub(/\\/, "\\\\") \ + .gsub(/"/, "\\\\\"") \ + .gsub(/\n/, "\\\\n") + "\"" + else + obj + end + when nil + "nil" + else + obj.to_s + end +end -- cgit v1.2.3