Topic: REPL in a webpage.

Hi! I am a computer science student and I have a problem I just can't seem to find an answer to. I would like to embed a an read-eval-print-loop in a website. Essentially, I'd like a window that mimics a console: the user types in some random text, it is processed, a value is returned and displayed, and then it waits for the user's input again*.  Exactly like a console.

I am new to Ruby and I have only just begun looking at Rails. In fact, I have absolutely no experience in web programming whatever. So even if someone could just point me in the right direction, I'd appreciate it.

* FYI, I am trying to create an online version of my research project: an interpreter and interactive environment for a small functional language.

Re: REPL in a webpage.

You would basically do something like this:


<%= content_tag :div, nil, :id => :response %>

<%- form_remote_tag :url => new_process_ruby_path, :method => :post do %>
  <%= label_tag :ruby_code, "Enter some ruby code:"
        <%= text_area_tag :ruby_code, "" %>
  <%= submit_tag "eval!" %>
<%- end -%>
  def new
    @ruby_code = params[:ruby_code]
page.replace_html :response, eval(@ruby_code)

Re: REPL in a webpage.

Great! Thank you very much! I will try it out as soon as I can.