instance method
tok
Ruby on Rails 3.0.20
Since v2.3.18 Last seen in v3.0.20Available in: v2.3.18 v3.0.20
Signature
tok(s)
Scans the first token in s and returns a 3-element list, or nil if s does not begin with a valid token.
The first list element is one of ‘{’, ‘}’, ‘:’, ‘,’, ‘[’, ‘]’, :val, :str, and :space.
The second element is the lexeme.
The third element is the value of the token for :val and :str, otherwise it is the lexeme.
Parameters
-
sreq
Source
# File activesupport/lib/active_support/json/backends/okjson.rb, line 204
def tok(s)
case s[0]
when ?{ then ['{', s[0,1], s[0,1]]
when ?} then ['}', s[0,1], s[0,1]]
when ?: then [':', s[0,1], s[0,1]]
when ?, then [',', s[0,1], s[0,1]]
when ?[ then ['[', s[0,1], s[0,1]]
when ?] then [']', s[0,1], s[0,1]]
when ?n then nulltok(s)
when ?t then truetok(s)
when ?f then falsetok(s)
when ?" then strtok(s)
when Spc then [:space, s[0,1], s[0,1]]
when ?\t then [:space, s[0,1], s[0,1]]
when ?\n then [:space, s[0,1], s[0,1]]
when ?\r then [:space, s[0,1], s[0,1]]
else numtok(s)
end
end
Defined in activesupport/lib/active_support/json/backends/okjson.rb line 204
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::OkJson