Listing Ruby keywords

Discussion in 'Ruby' started by John Maclean, Jan 2, 2006.

  1. John Maclean

    John Maclean Guest

    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
    John Maclean, Jan 2, 2006
    #1
    1. Advertising

  2. John Maclean

    George Ogata Guest

    John Maclean <> 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.
    George Ogata, Jan 2, 2006
    #2
    1. Advertising

  3. On 1/2/06, George Ogata <> wrote:
    > John Maclean <> 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. ;)
    Wilson Bilkovich, Jan 2, 2006
    #3
  4. John Maclean

    Gene Tani Guest

    George Ogata wrote:
    > John Maclean <> 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, Jan 2, 2006
    #4
  5. John Maclean

    Gene Tani Guest

    Gene Tani, Jan 2, 2006
    #5
  6. John Maclean

    George Ogata Guest

    "Gene Tani" <> writes:

    > George Ogata wrote:
    >> John Maclean <> 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.
    George Ogata, Jan 2, 2006
    #6
  7. 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
    Devin Mullins, Jan 2, 2006
    #7
  8. John Maclean

    Ryan Davis Guest

    Ryan Davis, Jan 4, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce
    Replies:
    0
    Views:
    676
    Bruce
    Aug 13, 2004
  2. valentin tihomirov

    Advantages of denying keywords as identifiers

    valentin tihomirov, Dec 17, 2004, in forum: VHDL
    Replies:
    8
    Views:
    503
    Mike Treseler
    Dec 28, 2004
  3. Jim Menard

    NYC Ruby job listing

    Jim Menard, Sep 28, 2004, in forum: Ruby
    Replies:
    10
    Views:
    193
    Andres Salomon
    Sep 29, 2004
  4. Chris Roos

    Ruby keywords vs methods

    Chris Roos, Sep 16, 2006, in forum: Ruby
    Replies:
    10
    Views:
    197
    Jeremy Tregunna
    Sep 16, 2006
  5. David A. Black
    Replies:
    18
    Views:
    273
    James Britt
    Jul 1, 2009
Loading...

Share This Page