aboutsummaryrefslogtreecommitdiff
path: root/ruby/printer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ruby/printer.rb')
-rw-r--r--ruby/printer.rb23
1 files changed, 23 insertions, 0 deletions
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