[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Listing Ruby keywords

John Maclean

1/2/2006 4:56:00 AM

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.

--
John Maclean
MSc (DIC)
07739 171 531



8 Answers

George Ogata

1/2/2006 7:36:00 AM

0

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.

Wilson Bilkovich

1/2/2006 7:49:00 AM

0

On 1/2/06, George Ogata <g_ogata@optushome.com.au> wrote:
> 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.

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


Gene Tani

1/2/2006 8:57:00 AM

0


George Ogata wrote:
> 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?

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

Gene Tani

1/2/2006 9:07:00 AM

0


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/avoiding-ruby-key...

George Ogata

1/2/2006 9:15:00 AM

0

"Gene Tani" <gene.tani@gmail.com> writes:

> George Ogata wrote:
>> 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?
>
> 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.

Christian Neukirchen

1/2/2006 1:48:00 PM

0

Wilson Bilkovich <wilsonb@gmail.com> writes:

> On 1/2/06, George Ogata <g_ogata@optushome.com.au> wrote:
>> 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.
>>
> 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 simply look into the "keywords" file in the Ruby sources...

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Devin Mullins

1/2/2006 7:10:00 PM

0

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

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



Ryan Davis

1/4/2006 2:29:00 AM

0


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.zens...Languages/Ruby/Quick...

--
ryand-ruby@zenspider.com - Seattle.rb - http://www.zens...
seattle.rb
http://blog.zens... - http://rubyforge.org/proje...