Reply to topic
the beauty of Ruby
pmeserve
HostMySite Tech

Joined: 19 Mar 2004
Posts: 178
Reply with quote
A "closure" in CF:
Code:
<cfscript>
function select(collection,closure) {
   var result = structNew();
   var e = 0;
   for (e in collection) {
      if (closure.call(collection[e])) {
         result[e] = collection[e];
      }
   }
   return result;
}
</cfscript>

<cfset emps = structNew() />
<cfset e = structNew() />
<cfset e.name = "Sean" />
<cfset e.isManager = true />
<cfset emps[e.name] = e />
<cfset e = structNew() />
<cfset e.name = "Matias" />
<cfset e.isManager = false />
<cfset emps[e.name] = e />
<cfset e = structNew() />
<cfset e.name = "Paul" />
<cfset e.isManager = false />
<cfset emps[e.name] = e />

<cfset mgrs = select(emps,cf.new("e.isManager","e")) />

In Ruby:

Code:
emps = [ {:name => "Sean", :isManager => true},
         {:name => "Matias", :isManager => false},
         {:name => "Paul", :isManager => false} ]

mgrs = emps.select{|e| e[:isManager] }

Or if isManager was a method in the emp class, the last line could be:
Code:
emps.select(&:isManager)
CF
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 340
Reply with quote
That's interesting, because CF is one of the easier languages. I wonder what it looks like in Java Very Happy or .net.
Hmmm...
Jason101
Forum Regular

Joined: 14 Mar 2006
Posts: 547
Location: Harrisburg, PA
Reply with quote
Maybe I should give this Rubby stuff a try. Cool I "Tried" ColdFusion 3 years ago when I was a HardCore PHP guy and now, I cringe at the idea of even thinking about writing an application in PHP.
Same here
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 340
Reply with quote
Maybe I should give this Rubby stuff a try. Cool I "Tried" ColdFusion 3 years ago when I was a HardCore PHP guy and now, I cringe at the idea of even thinking about writing an application in PHP
Jason, same here in terms of CF and Ruby/Rails. At first I hated Rail's conventions, but when I tried it again, I was sold. CF seems counter-productive, and too expensive.[/quote]
the beauty of Ruby
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic