Listing Ruby keywords

J

John Maclean

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.
 
G

George Ogata

John Maclean said:
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.
 
W

Wilson Bilkovich

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.

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. ;)
 
G

Gene Tani

George said:
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?

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
 
G

George Ogata

Gene Tani said:
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

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.
 
D

Devin Mullins

Wilson said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top