Rosetta Code/Rank languages by popularity: Difference between revisions
Content added Content deleted
(→{{header|Ruby}}: re-write to remove limits on number of categories.) |
(→{{header|Ruby}}: use the Programming_Languages category) |
||
Line 460: | Line 460: | ||
<lang ruby>require 'rosettacode' |
<lang ruby>require 'rosettacode' |
||
⚫ | |||
module RosettaCode |
|||
⚫ | |||
def RosettaCode.rc_all_categories |
|||
⚫ | |||
query = { |
|||
lang = (lang.split(":"))[-1] |
|||
"action" => "query", |
|||
RosettaCode.rc_tasks(lang) do |task| |
|||
"list" => "allcategories", |
|||
langs[lang] += 1 |
|||
"format" => "xml", |
|||
"aclimit" => 500, |
|||
} |
|||
categories = [] |
|||
while true |
|||
url = rc_url "api.php", query |
|||
doc = REXML::Document.new open(url) |
|||
REXML::XPath.each(doc, "//c") do |category| |
|||
categories << category.text |
|||
end |
|||
continue = REXML::XPath.first(doc, "//query-continue") |
|||
break if continue.nil? |
|||
cm = REXML::XPath.first(continue, "allcategories") |
|||
query["acfrom"] = cm.attribute("acfrom").value |
|||
end |
|||
categories |
|||
end |
|||
end |
|||
$stdout.sync=true |
|||
⚫ | |||
RosettaCode.rc_all_categories.each do |category| |
|||
⚫ | |||
⚫ | |||
categories[category] += 1 |
|||
end |
end |
||
end |
end |
||
puts "There are #{ |
puts "There are #{langs.length} languages" |
||
puts "the top 10:" |
puts "the top 10:" |
||
langs.sort_by {|key,val| val}.reverse.each_with_index do |pair, i| |
|||
lang, count = pair |
|||
puts "#{i+1}. #{count} - #{ |
puts "#{i+1}. #{count} - #{lang}" |
||
end</lang> |
end</lang> |
||
<pre>There are |
<pre>There are 139 languages |
||
the top 10: |
the top 10: |
||
1. 313 - Tcl |
1. 313 - Tcl |
||
2. |
2. 270 - Python |
||
3. |
3. 236 - Ada |
||
4. |
4. 232 - Ruby |
||
5. |
5. 229 - C |
||
6. |
6. 222 - Perl |
||
7. |
7. 209 - OCaml |
||
8. |
8. 206 - Java |
||
9. |
9. 200 - Haskell |
||
10. |
10. 198 - ALGOL 68</pre> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |