Is Ruby a scripting language or an interpreted language?

前端 未结 3 1966
醉话见心
醉话见心 2021-01-31 16:49

I just noticed that in the wikipedia page of Ruby, this language is defined as interpreted language.
I understood that probably there\'s something missing in my background.

相关标签:
3条回答
  • 2021-01-31 17:11

    Things aren't just black and white. At the very least, they're also big and small, loud and quiet, blue and orange, grey and gray, long and short, right and wrong, etc.

    Interpreted/compiled is just one way to categorize languages, and it's completely independent from (among countless other things) whether you call the same language a "scripting language" or not. To top it off, it's also a broken classification:

    • Interpreted/compiled depends on the language implementation, not on the language (this is not just theory, there are indeed quite a few languages for which both interpreters and compilers exist)
    • There are language implementations (lots of them, including most Ruby implementations) that are compilers, but "only" compile to bytecode and interpret that bytecode.
    • There are also implementations that switch between interpreting and compiling to native code (JIT compilers).

    You see, reality is a complex beast ;) Ruby is, as mentioned above, frequently compiled. The output of that compilation is then interpreted, at least in some cases - there are also implementations that JIT-compile (Rubinius, and IIRC JRuby compiles to Java bytecode after a while). The reference implementation has been a compiler for a long time, and IIRC still is. So is Ruby interpreted or compiled? Neither term is meaningful unless you define it ;)

    But back to the question: "Scripting language" isn't a property of the language either, it depends on how the language is used - namely, whether the language is used for scripting tasks. If you're looking for a definition, the Wikipedia page on "Scripting language" may help (just don't let them confuse you with the notes on implementation details such as that scripts are usually interpreted). There are indeed a few programs that use Ruby for scripting tasks, and there are doubtless numerous free-standing Ruby programs that would likely qualify as scripts (web scraping, system administration, etc).

    So yes, I guess one can call Ruby a scripting language. Of course that doesn't mean a ruby on rails web app is just a script.

    0 讨论(0)
  • 2021-01-31 17:21

    Yes.

    Detailed response:

    A scripting language is typically used to control applications that are often not written in this language. For example, shell scripts etc. can call arbitrary console applications.

    Ruby is a general purpose dynamic language that is frequently used for scripting.

    You can make arbitrary system calls using backtick notation like below.

    `<system command>`
    

    There are also many excellent Ruby gems such as Watir and RAutomation for automating web and native GUIs.

    For definition of scripting language, see here.

    0 讨论(0)
  • 2021-01-31 17:31

    The term 'scripting language' is very broad, and it can include both interpreted and compiled languages. Ruby in particular, might compiled or interpreted depending on what particular implementation we're using - for instance, JRuby gets compiled to bytecode, whereas CRuby (Ruby's reference implementation) is interpreted

    0 讨论(0)
提交回复
热议问题