Try Ruby, the Batch File

May 9th 21:40
by why

I love this! Raggi has reduced Try Ruby into a 682 byte batch file for Windows.

@echo tryurl="http://tryruby.hobix.com/irb?cmd=";function wget(url,hdrs){var http=WScript.CreateObject("Microsoft.XMLHTTP");http.open("GET",url,false);for(var k in hdrs){http.setRequestHeader(k,hdrs[k]);};http.send("");return http.responseText;}sess=wget(tryurl+escape("!INIT!IRB!"),{});WScript.Echo("Interactive Ruby ready. (send ^D to exit)");WScript.StdOut.Write(">> ");WScript.StdIn.Read(0);while(true){cmd=WScript.StdIn.ReadLine();resp="";ps=">> ";if(cmd=="\004")break;if(cmd){resp=wget(tryurl+escape(cmd).replace('+','%2B'),{'Cookie': '_session_id='+sess});ps="..";if(resp){WScript.StdOut.Write(resp);ps=">>";}}WScript.StdOut.Write(ps+" ");}>t.js
@cscript//Nologo t.js&del t.js

Toss try.bat and try.sh on a USB stick and you’ve got a cross-platform Ruby console in just a few K. Next up: the DS Lite??

3 comments

acrylic

said on May 9th 22:31

A small patch for try.sh:

--- try.sh.orig 2007-05-09 23:22:38.000000000 -0400
+++ try.sh      2007-05-09 23:22:57.000000000 -0400
@@ -32,7 +32,7 @@
         resp="$($wget --header "Cookie: _session_id=$sess" "$tryurl$(urlx "$cmd")")"
         ps=".."
         if [ -n "$resp" ] ; then
-            echo $resp
+            printf "$resp\n"
             ps=">>"
         fi
     fi

Before patch:

Interactive Ruby ready.
>> help
NameError: uninitialized constant IRB::ExtendCommandBundle::ExtendCommand from (eval):3:in `irb_help' from (eval):9:in `send' from (eval):9:in `help' from (irb):1
>> 

After patch:

Interactive Ruby ready.
>> help
NameError: uninitialized constant IRB::ExtendCommandBundle::ExtendCommand
        from (eval):3:in `irb_help'
        from (eval):9:in `send'
        from (eval):9:in `help'
        from (irb):1
>> 

patches

said on May 11st 06:26

There’s been some updates–two bug fixes both affecting the escaping of the “+”. The first was a mistake I made not paying attention to the escaping of the % character.

The second was a bug in the original .js source, where ‘+’ needs to be replaced by ‘/\+/g’ in order to support statements with more than one ‘+’ operator.

Some limited more details here: ruby for windows in under 700 bytes

patches double post

said on May 11st 06:27

Did I mention it’s down to 640 bytes? ;-)

Comments are closed for this entry.