Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a definitive reference document for Ruby syntax? [closed]

Tags:

I'm searching for a definitive document on Ruby syntax. I know about the definitive documents for the core API and standard library, but what about the syntax itself? For instance, such a document should cover: reserved words, string literals syntax, naming rules for variables/classes/modules, all the conditional statements and their permutations, and so forth.

I know there are many books and tutorials, yes, but every one of them is essentially a tutorial, each one having a range of different depth and focus. They will all, by necessity of brevity and narrative flow, omit certain details of the language that the author deems insignificant.

For instance, did you know that you can use a case statement without an initial case value, and it will then execute the first true when clause? Any given Ruby book or tutorial may or may not cover that particular lesser-known functionality of the case syntax. It's not discussed in the section in "Programming Ruby" about case statements. But that is just one small example.

So far the best documentation I've found is the rubyspec project, which appears to be an attempt to write a complete test suite for the language. That's not bad, but it's a bit hard to use from a practical standpoint as a developer working on my own projects.

Am I just missing something or is there really no definitive readable document defining the whole of Ruby syntax?

like image 322
Yetanotherjosh Avatar asked May 02 '10 19:05

Yetanotherjosh


1 Answers

The only document that can be reasonably described as "definitive" is the source code of parse.y in the YARV source tree.

The ISO Draft Specification contains a 39 page appendix with a summary of the grammar. Note, however, that ISO Ruby is a minimal subset of the intersection of Ruby 1.8 and 1.9. IOW: it doesn't describe anything that is only in 1.8 or only in 1.9 (so, the syntax additions in 1.9 like stabby proc and symbol hashes aren't described), nor does it describe everything in that intersection. ISO Ruby is a bit like ISO HTML in that regard.

The RubySpec project contains executable specifications for the Ruby language. It doesn't contain an explicit specification of the grammar, though. The only specification of the grammar is implicit in the examples themselves. Also, because RubySpec is an example-based spec, it can only show you specific examples of valid Ruby code, but it cannot tell you all possible valid Ruby programs like a grammar spec could. And, because RubySpec is itself executable Ruby code, it can only show you valid examples, not invalid ones.

The last thing that could be considered definitive is the book The Ruby Programming Language by David Flanagan and Yukihiro "matz" Matsumoto.

Note, however, that "the whole of Ruby syntax" is a rather daunting task, because Ruby's syntax is insanely complicated with a ginormous amount of weird corner cases.

like image 77
Jörg W Mittag Avatar answered Oct 12 '22 02:10

Jörg W Mittag