Project

General

Profile

Actions

Misc #15744

open

Improvement needed to documentation of 'Literals'

Added by CaryInVictoria (Cary Swoveland) over 5 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
[ruby-core:92112]

Description

Documentation of "Literals" for v2.6.0 is given here: https://docs.ruby-lang.org/en/2.6.0/syntax/literals_rdoc.html. (I don't think it has been changed for some time.) It gives examples of literals but does not provide a definition. It is comparable to defining an array by giving a few examples. I believe a definition is needed.

I would like to suggest a definition, but I confess I don't know what a Ruby literal is. A definition is attempted at this Wiki for computer programming generally: https://en.wikipedia.org/wiki/Literal_(computer_programming).

I suspect a Ruby literal is an object whose value is in some sense "known" at compile-time. For example, I would think 1, 1.0 and { a: [1, 'cat', ['dog', ['pig', ..10]]] } are literals but { v=>1, 2=>3 } in h = { v=>1, 2=>3 }, v being a variable, is not. Or is it? If the previous line of code had been v=3, Ruby could, at compile-time, infer that the line could be replaced with h = {3=>1, 2=>3}, in which case it would be "known". This example is meant to illustrate why I earlier said "in some sense".

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0