The eval side of Ruby
eval("puts 'Hello World'")
output:
Hello World
DZone Snippets > jrobertson > dynamic
12382 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
James Robertson http://www.r0bertson.co.uk
eval("puts 'Hello World'")
Hello World
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>dynalert</title> <meta http-equiv="Content-Type" content="type=text/html; charset=ISO-8859-1" /> <script type="text/javascript" src="dynalert.js"></script> </head> <body> <p id="i1">123 </p><input type="button" value="go" onclick="update()" /> </body> </html>
function populatePage(results){ eval(results); } //send the update function update() { var strServer = "dynalert.cgi"; url2 = ""; SubmitRBData(strServer,"?" + url2); } function SubmitRBData(strUrl, strPostFields) { http.open("GET", strUrl + strPostFields, true); http.onreadystatechange = handleHttpResponse; http.send(null); } function handleHttpResponse() { if (http.readyState == 4) { if (http.status == 200) { results = http.responseText; populatePage(results); // string response } } } function getHTTPObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } var http = getHTTPObject(); // We create the HTTP Object
#!/usr/bin/ruby # dynalert.cgi require 'cgi' cgi = CGI.new #title = cgi['title'] puts "Content-Type: text/html" puts puts "function transcript(){ alert('and Bob said this idea might work.');}" puts "alert('this is a success');" puts "alert('we can now pass back anything we like');" puts "transcript();" puts "oNew = document.createElement('strong');" puts "oNew.innerHTML = 'yes - this is bold text';" puts "document.getElementById('i1').appendChild(oNew);"