Module: EvalIn

Defined in:
lib/eval_in.rb,
lib/eval_in/http.rb,
lib/eval_in/mock.rb,
lib/eval_in/client.rb,
lib/eval_in/result.rb,
lib/eval_in/constants.rb

Defined Under Namespace

Modules: Client, HTTP Classes: Mock, Result

Constant Summary collapse

VERSION =
'0.2.0'
EvalInError =
Class.new StandardError
RequestError =
Class.new EvalInError
ResultNotFound =
Class.new EvalInError
KNOWN_LANGUAGES =

Examples:

Generated with

nokogiri https://eval.in -e 'puts $_.xpath("//option/@value")'
%w[
  c/gcc-4.4.3
  c/gcc-4.9.1
  c++/c++11-gcc-4.9.1
  c++/gcc-4.4.3
  c++/gcc-4.9.1
  coffeescript/node-0.10.29-coffee-1.7.1
  fortran/f95-4.4.3
  haskell/hugs98-sep-2006
  io/io-20131204
  javascript/node-0.10.29
  lua/lua-5.1.5
  lua/lua-5.2.3
  ocaml/ocaml-4.01.0
  php/php-5.5.14
  pascal/fpc-2.6.4
  perl/perl-5.20.0
  python/cpython-2.7.8
  python/cpython-3.4.1
  ruby/mri-1.0
  ruby/mri-1.8.7
  ruby/mri-1.9.3
  ruby/mri-2.0.0
  ruby/mri-2.1
  slash/slash-head
  assembly/nasm-2.07
]

Class Method Summary collapse

Class Method Details

.call(code, options = {}) ⇒ Result

Returns the relevant data from the evaluated code.

Examples:

result = EvalIn.call 'puts "hello, #{gets}"', stdin: 'world', language: "ruby/mri-2.1"
result.output # => "hello, world\n"

Parameters:

  • code (String)

    the code to evaluate.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :language (String)

    Mandatory, a language recognized by eval.in, such as any value in KNOWN_LANGUAGES.

  • :url (String)

    Override the url to post the code to

  • :stdin (String)

    Will be passed as standard input to the script

  • :context (String)

    Will be included in the user agent

Returns:

  • (Result)

    the relevant data from the evaluated code.



15
16
17
18
# File 'lib/eval_in.rb', line 15

def self.call(code, options={})
  url = Client.post_code(code, options)
  fetch_result url, options
end

.fetch_result(raw_url, options = {}) ⇒ Object

Examples:

result = EvalIn.fetch_result "https://eval.in/147.json"
result.output # => "Hello Charlie! "

Parameters:

  • url (String)

    the url with the result

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :context (String)

    Will be included in the user agent



26
27
28
29
# File 'lib/eval_in.rb', line 26

def self.fetch_result(raw_url, options={})
  raw_json_url = HTTP.jsonify_url(raw_url)
  Client.build_result Client.fetch_result_json(raw_json_url, options)
end