That code is quite interesting actually. John did you write it?

The first line (q= ...) defines a lambda, that is a proc, that is a
method that can be assigned to a variable.

It's equal to

def q(str)
  if str.match(/;q=/)
    $'.to_f # $' returns the string that follows the matched part
  else
    1
  end
end

The second line uses Array#collect to build an array of size-two
arrays. Each one has the result of q as first element and the language
code as second element.

The last part sorts this array by priority (which is the result of q)
and then collects only the language names.

The final result then is an array of languages ordered by priority.

> q = lambda { |str| /;q=/ =~ str ? Float($') : 1 }
> langs = langs.collect do |ele|
>   [q.call(ele), ele.split(/;/)[0].downcase]
> end.sort { |l, r| r[0] <=> l[0] }.collect { |ele| ele[1] }
_______________________________________________
Radiant mailing list
Post:   [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to