I was looking at the Ruby documentation, and am wondering if everything is an object then \'keywords\' are objects as well, correct? And if so, where are they defined in ruby?<
The keywords are not objects but defined in the parser which can be found in parse.y
in the Ruby source. Here's the relevant part from that file:
reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
| keyword_BEGIN | keyword_END
| keyword_alias | keyword_and | keyword_begin
| keyword_break | keyword_case | keyword_class | keyword_def
| keyword_defined | keyword_do | keyword_else | keyword_elsif
| keyword_end | keyword_ensure | keyword_false
| keyword_for | keyword_in | keyword_module | keyword_next
| keyword_nil | keyword_not | keyword_or | keyword_redo
| keyword_rescue | keyword_retry | keyword_return | keyword_self
| keyword_super | keyword_then | keyword_true | keyword_undef
| keyword_when | keyword_yield | keyword_if | keyword_unless
| keyword_while | keyword_until
;
If you want to know more about the Ruby parser, look at the presentation Hacking parse.y from RubyConf 2009 or Parse.y famtour from Ruby Kaigi 2011.
Also, a lot of the methods that are available everywhere (like e.g. puts
) are defined in the Kernel module.
EDIT: There's also a list of key words in the documentation, thanks @antinome for pointing that out.