Services Spotlight:

Finding Reserved Words or Keywords In Ruby

Written By Corlew Solutions
Updated February 13, 2014
Published February 8, 2014
Why Corlew Solutions?

We write great software and provide amazing technical support. Contact us today if you need help with a software project:

Article Technology Info

This article discusses the following technologies:

  • Ruby - A dynamic, reflective, object-oriented programming language.
    (website | download | docs)

There are many web pages that list the reserved keywords in Ruby, but what if you want to make absolutely sure the “other guy’s” list is correct? Some webpages don’t specify which version of Ruby they are referencing and the keyword list does change (although granted, not that often). For example, the __ENCODING__ keyword was added in Ruby 1.9.1. If you want to be absolutely sure about the reserved words list in Ruby, the best way is to go straight to the source code:

Option 1

All of the Ruby source code is available on the Ruby GitHub page. Inside the defs folder you’ll find a keywords file. Open it up an enjoy the goodness.

Note: For Ruby 1.8.7 and earlier there is no defs folder. The keywords file lived in the root directory.

The following list will jump you straight to the keywords file for various versions of Ruby.

Option 2

You can download the source code directory from the Ruby Lang website and navigate to the same directories as above.

Ruby 2.1.0 Reserved Words List

Here is a quick reference for the 41 keywords used in Ruby 2.1.0:

__ENCODING__ def in self
__LINE__ defined? module super
__FILE__ do next then
BEGIN else nil true
END elsif not undef
alias end or unless
and ensure redo until
begin false rescue when
break for retry while
case if return yield
class      

We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!

Corlew Solutions is a Web Design and Web Application Development company based in Fairfax Virginia, minutes away Washington D.C. If you're looking for great web design from the Northern Virginia area or web design from the Washington D.C. area we can help. Contact Us today!

comments powered by Disqus