Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
irb/ruby-token.rb - ruby tokens
$Release Version: 0.9.6$
$Revision: 28158 $
by Keiju ISHITSUKA(keiju@ruby-lang.org)
–
{reading => token_class} {reading => [token_class, *opt]}
# File irb/ruby-token.rb, line 242
def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts)
token_n = token_n.id2name if token_n.kind_of?(Symbol)
if RubyToken.const_defined?(token_n)
IRB.fail AlreadyDefinedToken, token_n
end
token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
if reading
if TkReading2Token[reading]
IRB.fail TkReading2TokenDuplicateError, token_n, reading
end
if opts.empty?
TkReading2Token[reading] = [token_c]
else
TkReading2Token[reading] = [token_c].concat(opts)
end
end
TkSymbol2Token[token_n.intern] = token_c
end
# File irb/ruby-token.rb, line 76
def Token(token, value = nil)
case token
when String
if (tk = TkReading2Token[token]).nil?
IRB.fail TkReading2TokenNoKey, token
end
tk = Token(tk[0], value)
if tk.kind_of?(TkOp)
tk.name = token
end
return tk
when Symbol
if (tk = TkSymbol2Token[token]).nil?
IRB.fail TkSymbol2TokenNoKey, token
end
return Token(tk[0], value)
else
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
token.new(@prev_seek, @prev_line_no, @prev_char_no)
else
token.new(@prev_seek, @prev_line_no, @prev_char_no, value)
end
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.