Forum: Ruby Listing Ruby keywords

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
508861510639b56d61eb30e6a28b01d9?d=identicon&s=25 John Maclean (Guest)
on 2006-01-02 05:58
(Received via mailing list)
Is there a simple way to find out all or most of the built-in keywords?
I know that if a keyword's in a ruby script that the debugger will tell
you but I'd like to know before hand, in other words when I'm actually
writing the scripts.
851246810c70dbfcc1815c636b054562?d=identicon&s=25 George Ogata (Guest)
on 2006-01-02 08:44
(Received via mailing list)
John Maclean <info@jayeola.org> writes:

> Is there a simple way to find out all or most of the built-in
> keywords? I know that if a keyword's in a ruby script that the
> debugger will tell you but I'd like to know before hand, in other
> words when I'm actually writing the scripts.

Can't use an editor with syntax coloring?  ;-)

The emacs ruby-mode colors these as keywords:

	       "alias"
	       "and"
	       "begin"
	       "break"
	       "case"
	       "catch"
	       "class"
	       "def"
	       "do"
	       "elsif"
	       "else"
	       "fail"
	       "ensure"
	       "for"
	       "end"
	       "if"
	       "in"
	       "module"
	       "next"
	       "not"
	       "or"
	       "raise"
	       "redo"
	       "rescue"
	       "retry"
	       "return"
	       "then"
	       "throw"
	       "super"
	       "unless"
	       "undef"
	       "until"
	       "when"
	       "while"
	       "yield"

And these as special variables:

  nil, self, true, false, __FILE__, __LINE__

Aside from that I can only think of:

  BEGIN, END, defined?

You could also try searching the list archives.

HTH.
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-01-02 08:50
(Received via mailing list)
On 1/2/06, George Ogata <g_ogata@optushome.com.au> wrote:
>
>                "else"
>                "raise"
>                "when"
>
> You could also try searching the list archives.
>
> HTH.

Or you could make a script that tries to assign to local variables
with every possible name combination, and keeps track of which ones
throw exceptions. ;)
9dfe8c734b0f9b37a4e218425c0a2138?d=identicon&s=25 Gene Tani (Guest)
on 2006-01-02 09:59
(Received via mailing list)
George Ogata wrote:
>
> 	       "else"
> 	       "raise"
> 	       "when"
> 	       "while"
> 	       "yield"
>
> And these as special variables:
>
>   nil, self, true, false, __FILE__, __LINE__
>
> Aside from that I can only think of:
>
>   BEGIN, END, defined?

The Nutshell doesn't list "raise" as a keyword

class Blah
    def testraise
        raise=3
        "raise local var: #{raise}"
    end
end

a=Blah.new()
p a.testraise    # =>"raise local var: 3"

and i always wondered why public, protected and private weren't
keywords also
9dfe8c734b0f9b37a4e218425c0a2138?d=identicon&s=25 Gene Tani (Guest)
on 2006-01-02 10:08
(Received via mailing list)
Wilson Bilkovich wrote:
> On 1/2/06, George Ogata <g_ogata@optushome.com.au> wrote:
> > John Maclean <info@jayeola.org> writes:
> >
> Or you could make a script that tries to assign to local variables
> with every possible name combination, and keeps track of which ones
> throw exceptions. ;)

or code like mental

http://moonbase.rydia.net/mental/blog/programming/...
851246810c70dbfcc1815c636b054562?d=identicon&s=25 George Ogata (Guest)
on 2006-01-02 10:24
(Received via mailing list)
"Gene Tani" <gene.tani@gmail.com> writes:

>> The emacs ruby-mode colors these as keywords:
>> 	       "elsif"
>> 	       "or"
>> 	       "until"
>>   BEGIN, END, defined?
> a=Blah.new()
> p a.testraise    # =>"raise local var: 3"
>
> and i always wondered why public, protected and private weren't
> keywords also

Because they're not really keywords; they're methods of Module.  Try
ri on them... :-)

On closer examination, catch, fail, raise and throw aren't keywords
either.  It's handy to have them highlighted though.
7264fb16beeea92b89bb42023738259d?d=identicon&s=25 Christian Neukirchen (Guest)
on 2006-01-02 17:15
(Received via mailing list)
Wilson Bilkovich <wilsonb@gmail.com> writes:

> throw exceptions. ;)
Or you could simply look into the "keywords" file in the Ruby sources...
918c6daad03c85e51ad1a11f57017947?d=identicon&s=25 Devin Mullins (Guest)
on 2006-01-02 20:12
(Received via mailing list)
Wilson Bilkovich wrote:

>Or you could make a script that tries to assign to local variables
>with every possible name combination, and keeps track of which ones
>throw exceptions. ;)
>
>
Or you could bookmark
http://phrogz.net/ProgrammingRuby/language.html#names

raise, public, private, and protected aren't keywords -- they're
methods. As such, you *can* make variables with their names, and use
self.xxx to invoke the method.

Devin
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2006-01-04 03:31
(Received via mailing list)
On Jan 1, 2006, at 8:55 PM, John Maclean wrote:

> Is there a simple way to find out all or most of the built-in
> keywords? I know that if a keyword's in a ruby script that the
> debugger will tell you but I'd like to know before hand, in other
> words when I'm actually writing the scripts.

http://www.zenspider.com/Languages/Ruby/QuickRef.html#3
This topic is locked and can not be replied to.