First off, the example that follows the lead of the PHP example (albeit a little more complicated):
<cfset who = "Sean" />
<cftimer label="Executing Ruby" type="outline">
<script:ruby>
# since we need to return the last expression in the script
# we run other code first, unless the PHP example:
# set a page level variable in ColdFusion:
$coldfusion["greeting"] = "wibble"
# read a URL variable and set a session variable in ColdFusion:
$test = $url["test"]
if $test then
$session["what"] = $url["test"]
else
$session["what"] = "test was not passed as a URL variable"
end
# this builds a single string which is the result of the script:
"Hi " + $coldfusion["who"] + "<br />" +
$session["marker"] + "<br />" +
($test ? $test : "") + "<br />" +
$cgi["SCRIPT_FILENAME"] + "<br />"
</script:ruby>
</cftimer>
Unlike the PHP scripting engine, any actual output from Ruby is lost (puts, print) or, more accurately, written directly to the system console which is not very helpful. Instead, the last expression evaluated is converted to a string and used as output of the custom tag.
Here's another example showing a Ruby class used with a block and an iterator:
<script:ruby>
class Person
def initialize(firstName,lastName)
@firstName = firstName
@lastName = lastName
end
attr_reader :firstName, :lastName
end
people = [
Person.new("Ben","Forta"),
Person.new("Jason","Delmore"),
Person.new("Tim","Buntel")
]
people.collect {
|person|
person.firstName + " " + person.lastName + " rocks!<br />"
}
</script:ruby>
</cftimer>
Python, Groovy and Haskell are on my list. I may go through the entire Sun Scripting Engine list eventually (Awk, Tcl and a variety of strange pseudo-languages are there).


