Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6940043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:42:11+00:00 2026-05-27T12:42:11+00:00

I want to detect programming language with ruby For example: (PHP) $a = array(1,2,3);

  • 0

I want to detect programming language with ruby

For example:
(PHP)

$a = array("1","2","3");
print_r($a); 

(Ruby)

def index
end

etc.

What gem can do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:42:12+00:00Added an answer on May 27, 2026 at 12:42 pm

    Linguist might do that for you (it’s what GitHub uses to detect the primary languages in a project).

    If you’re looking to build your own, that would be a good place to start. Here are a few more notes on what else you might have to do in order to make one.

    File extensions are a good cheat. For example:

    • .rb – almost always ruby
    • .cpp – almost always C++
    • .h – could be C/C++

    …etc., then read the code line by line. There are usually common key words, or the placement of those words within the code that will tip you off pretty quickly as to what language it’s written in. A review of several “getting started” tutorial web sites for the languages that you want to support should give you a good summary of these things, without needing to actually learn the languages themselves. All you really need is a few unique things to each language that you can pick up on that makes a file definitively one language or another.

    You could also use a Bayesian learning filter (there is a module called Classifier in Ruby that appears to do this) to train a more flexible learning engine to identify code by language on its own. Since programming languages are highly structured text, it shouldn’t take very long for your learning software to get extremely good at identifying the language. If you wanted to go totally crazy, you could even train it to identify not only the language, but the minimum version of the language that the code can be compiled against. For example, in Java, they added generics at a particular point in the language’s life cycle. If you see the use of generics in the code, then you know that the source was written for a certain minimum version of Java, etc.

    A little more complex, but not much, will be questions like .erb files. Do you call those “Embedded Ruby”, do you call them “Ruby”, or do you count the lines of HTML vs. Ruby vs. JavaScript, and call it by the most numerous language, or do you just tag the file with ALL the found languages? I suppose that’s really more of a design decision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to detect duplicate values in a Java array. For example: int[] array
I want to detect the browser language so I can switch languages when people
I want to detect emails in text format so that I can put an
I want to detect if a string contains both numbers and letters. For example:
I am new in C programming Here i want to detect USB is inserted
I want to detect the automatic language from the device .Basically , I want
I am pretty new to programming and I want to know how to detect
I want to detect a div (dynamic content div) end, when user scroll down
I want to detect users' screen size and pass this into a charting application
i want to detect to see if an element was dragged out of container.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.