简体   繁体   中英

Is Ruby and JRuby syntax different?

This might be my worst question yet, but I am in the process of choosing Ruby vs. Jruby for a project that is in technology-research phase so syntax being the same is a minor concern for flexibility.

Are they two different syntaxes or do both look pretty much the same?

Short answer : They use the same syntax. There are slight differences in the objects and methods available, but the syntax is the same.

Longer answer : Ruby 1.9 uses a slightly different syntax than Ruby 1.8. JRuby originally lagged behind in 1.9 support, but is slowly catching up. If you are talking about Ruby 1.8 vs. JRuby, it's the same. If you're talking Ruby 1.9 vs. JRuby, then it is the same as long as you are using JRuby 1.6.0RC2 or later .

Compiler handles all 1.9 syntax now

ruby is a language. It has multiple implementations, but there is one reference implementation known as either MRI (Matz's ruby interpreter) or C-Ruby (because it's written in C). There is also a ruby specification project in progress, which attempts to document how ruby should behave rather than just "do what MRI does".

There are also multiple versions of ruby, 1.8.7 and 1.9.1 being the most commonly found these days.

With that being said, the goal of all implementations (including JRuby, Ironruby, Rubinius) is to be compliant with the spec, and therefore compatible. So you can write your "pure" ruby code and run it on whatever implementation is best.

Of course, different implementations have their own bugs, and their own level of compliance with the spec. And that is what you need to watch out for.

same syntax. only different with database connectivity ruby use MYSQL2 for database connectivity and jruby use jdbcmsql for database connectivity

required gem for jruby database connectivity is activerecord-jdbcmysql-adapter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM