Thursday 29 August 2013

Cool Railo thing I learned at the London Railo Group meeting last night

Last night was the first meeting of the London Railo Group. A bunch of people in the local London Railo community got together at the Pixl8 offices and had an informal catch-up and drank beer and ate pizza. There was only about a dozen people there, but I think it was a successful first meeting. Well done Alex Skinner for organising it, and Mark Drew for giving an impromptu presentation on some random Railo stuff he finds interesting.

One thing Mark showed us was the _toString() function one can put in a component, thus:

// ColourCollection.cfc
component {

    public ColourCollection function init(required array colours){
        variables.colours = arguments.colours;
        return this;

    public string function _toString(){
        return arrayToList(variables.colours);


Which then enables me to do this:

<!--- testToString.cfm --->
<cfset rainbow = new ColourCollection(["whero","karaka","kowhai","kakariki","kikorangi","tawatawa","mawhero"])>
    Output: #rainbow#<br>
    len(): #len(rainbow)#<br>
    listLen(): #listLen(rainbow)#<br>
    ucase(): #ucase(rainbow)#<br>

Which results in this:

Output: whero,karaka,kowhai,kakariki,kikorangi,tawatawa,mawhero
len(): 55
listLen(): 7

So given I have a _toString() method in my CFC, I can pass an object of that type to any situation which calls for a string, and the _toString() method will automatically be called. My _toString() method here is pretty contrived, but it demonstrates the point.

This is something I've been wanting in CFML for a long time, so good on Railo for adding it in.