diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-10 20:34:29 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-10 20:34:29 -0500 |
| commit | f705f0fce151863091ad77753105f0d15270edec (patch) | |
| tree | 788691596846567abec1606131c972d24211604c /ruby/printer.rb | |
| parent | 712af9efbe15a9a65c25ab92ee2a49c8e749ed3d (diff) | |
| download | mal-f705f0fce151863091ad77753105f0d15270edec.tar.gz mal-f705f0fce151863091ad77753105f0d15270edec.zip | |
Ruby: step0, step1
Diffstat (limited to 'ruby/printer.rb')
| -rw-r--r-- | ruby/printer.rb | 23 |
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 |
