Class: Campa::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/campa/printer.rb

Overview

Represents a Campa expression in a human readable form.

In general it tries to create a representation that is valid Campa code to make it easy(ier) to copy and paste stuff from the REPL to a file.

Examples:

some results produced by Printer

printer = Printer.new

printer.call("lol") #=> "lol"
printer.call("lol") #=> 123
printer.call(List.new("bbq", 420, List.new("yes"))) #=> ("bbq" 420 ("yes"))

Instance Method Summary collapse

Instance Method Details

#call(expr) ⇒ String

Returns human readable form (almost always valid code) of an Expression.

Parameters:

  • expr (Object)

    Campa expression to be respresented in human readable form

Returns:

  • (String)

    human readable form (almost always valid code) of an Expression



21
22
23
24
25
26
# File 'lib/campa/printer.rb', line 21

def call(expr)
  format = FORMATS.fetch(expr.class) do
    expr.is_a?(Context) ? :context : :default
  end
  send(format, expr)
end