class EvalIn::Result

The data structure containing the final result its attributes default to null-objects for their given type

Attributes

attribute_names[R]

Public Class Methods

new(attributes={}) click to toggle source
# File lib/eval_in/result.rb, line 13
def initialize(attributes={})
  attributes = attributes.dup
  self.exitstatus         = attributes.delete(:exitstatus)        || -1
  self.language           = attributes.delete(:language)          || ""
  self.language_friendly  = attributes.delete(:language_friendly) || ""
  self.code               = attributes.delete(:code)              || ""
  self.output             = attributes.delete(:output)            || ""
  self.status             = attributes.delete(:status)            || ""
  self.url                = attributes.delete(:url)               || ""
  stderr                  = attributes.delete(:stderr)            || $stderr
  stderr.puts "Unexpected attributes! #{attributes.keys.inspect}" if attributes.any?
end

Public Instance Methods

as_json() click to toggle source

Returns representation of the result built out of JSON primitives (hash, string, int) This is useful for composing JSON structures and only rendering the JSON string at the end

# File lib/eval_in/result.rb, line 28
def as_json
  self.class.attribute_names.each_with_object Hash.new do |name, attributes|
    attributes[name.to_s] = public_send name
  end
end
to_json() click to toggle source
# File lib/eval_in/result.rb, line 34
def to_json
  JSON.dump(as_json)
end