Feature #9319

Add constant RUBY_KEYWORDS or a similar way to output which keywords exist at runtime

Added by Robert A. Heiler over 1 year ago. Updated about 1 year ago.

[ruby-core:59386]
Status:Closed
Priority:Normal
Assignee:Zachary Scott

Description

Hi,

Would it be possible to list all keywords in Ruby, from within a running program?

Like RUBY_KEYWORDS or similar?

Reasoning: On IRB someone asked me if "in" is a keyword. I was not sure so I googled
because I could not remember right off the head (I later remembered that "in" must
be because it is used in a "for" loop).

It would be nice if we could ask ruby itself which keywords would be available,
i.e. stored in an array.

http://ruby-doc.org/docs/keywords/1.9/ has a nice description of all keywords
too, which is great.

History

#1 Updated by Robert A. Heiler over 1 year ago

Oops, I meant "IRC", not "IRB", but yeah from within running IRB it would be also nice of course. :)

#2 Updated by Zachary Scott over 1 year ago

Thanks for the report, I can put something together for this soon

#3 Updated by Zachary Scott over 1 year ago

  • Category set to doc
  • Status changed from Open to Assigned
  • Assignee set to Zachary Scott
  • Priority changed from 3 to Normal

#4 Updated by Zachary Scott over 1 year ago

I created the following file, but I'm not sure if we should add anything else. https://gist.github.com/zzak/8187842

The old 1.9 file which converted these keywords to methods and added expanded documentation for each one is nice. I'm not sure it helps us or won't just confuse people.

Basically I think we should just make this a file under ./doc and you can access it from irb or ri, as well as it being available in the api documentation.

#5 Updated by Zachary Scott about 1 year ago

  • Status changed from Assigned to Closed

We've added an rdoc file to the source tree that lists the current keywords of ruby, you can access it a couple of ways, such as:

$ ri ruby:keywords

or from irb:

help "ruby:keywords"

Also available in: Atom PDF