Returns the length of the queue.
Returns the replacement string.
ec = Encoding::Converter.new("euc-jp", "us-ascii") p ec.replacement #=> "?" ec = Encoding::Converter.new("euc-jp", "utf-8") p ec.replacement #=> "\uFFFD"
Sets the replacement string.
ec = Encoding::Converter.new("utf-8", "us-ascii", :undef => :replace) ec.replacement = "<undef>" p ec.convert("a \u3042 b") #=> "a <undef> b"
Returns true
if key
is a key in self
, otherwise false
.
Returns the number of referenced objects
Parses the given string into an abstract syntax tree, returning the root node of that tree.
RubyVM::AbstractSyntaxTree.parse("x = 1 + 2") # => #<RubyVM::AbstractSyntaxTree::Node:SCOPE@1:0-1:9>
If keep_script_lines: true
option is provided, the text of the parsed source is associated with nodes and is available via Node#script_lines
.
If keep_tokens: true
option is provided, Node#tokens
are populated.
SyntaxError
is raised if the given string is invalid syntax. To overwrite this behavior, error_tolerant: true
can be provided. In this case, the parser will produce a tree where expressions with syntax errors would be represented by Node
with type=:ERROR
.
root = RubyVM::AbstractSyntaxTree.parse("x = 1; p(x; y=2") # <internal:ast>:33:in `parse': syntax error, unexpected ';', expecting ')' (SyntaxError) # x = 1; p(x; y=2 # ^ root = RubyVM::AbstractSyntaxTree.parse("x = 1; p(x; y=2", error_tolerant: true) # (SCOPE@1:0-1:15 # tbl: [:x, :y] # args: nil # body: (BLOCK@1:0-1:15 (LASGN@1:0-1:5 :x (LIT@1:4-1:5 1)) (ERROR@1:7-1:11) (LASGN@1:12-1:15 :y (LIT@1:14-1:15 2)))) root.children.last.children # [(LASGN@1:0-1:5 :x (LIT@1:4-1:5 1)), # (ERROR@1:7-1:11), # (LASGN@1:12-1:15 :y (LIT@1:14-1:15 2))]
Note that parsing continues even after the errored expression.
Escape
only the tags of certain HTML elements in string
.
Takes an element or elements or array of elements. Each element is specified by the name of the element, without angle brackets. This matches both the start and the end tag of that element. The attribute list of the open tag will also be escaped (for instance, the double-quotes surrounding attribute values).
print CGI.escapeElement('<BR><A HREF="url"></A>', "A", "IMG") # "<BR><A HREF="url"></A>" print CGI.escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"]) # "<BR><A HREF="url"></A>"
Undo escaping such as that done by CGI.escapeElement()
print CGI.unescapeElement( CGI.escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG") # "<BR><A HREF="url"></A>" print CGI.unescapeElement( CGI.escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"]) # "<BR><A HREF="url"></A>"
Updates the digest using a given string and returns self.
The update() method and the left-shift operator are overridden by each implementation subclass. (One should be an alias for the other)
Returns digest_obj.digest_length().
Reads at most maxlen bytes from the stream. If buf is provided it must reference a string which will receive the data.
See IO#readpartial
for full details.
Return true
if the PRNG has been seeded with enough data, false
otherwise.
Returns whether the form contained multipart/form-data
Parses self
destructively and returns self
containing the rest arguments left unparsed.
Generate a random alphanumeric string.
The argument n specifies the length, in characters, of the alphanumeric string to be generated. The argument chars specifies the character list which the result is consist of.
If n is not specified or is nil, 16 is assumed. It may be larger in the future.
The result may contain A-Z, a-z and 0-9, unless chars is specified.
require 'random/formatter' Random.alphanumeric #=> "2BuBuLf3WfSKyQbR" # or prng = Random.new prng.alphanumeric(10) #=> "i6K93NdqiH" Random.alphanumeric(4, chars: [*"0".."9"]) #=> "2952" # or prng = Random.new prng.alphanumeric(10, chars: [*"!".."/"]) #=> ",.,++%/''."
Simple deprecation method that deprecates name
by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user of repl
(unless repl
is :none) and the year/month that it is planned to go away.
Is fetching of local and remote information enabled?
A Zlib::Inflate#inflate
wrapper
Check if YJIT is enabled.
Enable YJIT compilation. stats
option decides whether to enable YJIT stats or not. compilation_log
decides whether to enable YJIT compilation logging or not.
stats
:
false
: Don’t enable stats.
true
: Enable stats. Print stats at exit.
:quiet
: Enable stats. Do not print stats at exit.
log
:
false
: Don’t enable the log.
true
: Enable the log. Print log at exit.
:quiet
: Enable the log. Do not print log at exit.
Load extra data embed into binary format String
object.
When there is an invalid block with a keyword missing an end right before another end, it is unclear where which keyword is missing the end
Take this example:
class Dog # 1 def bark # 2 puts "woof" # 3 end # 4
However due to github.com/ruby/syntax_suggest/issues/32 the problem line will be identified as:
> class Dog # 1
Because lines 2, 3, and 4 are technically valid code and are expanded first, deemed valid, and hidden. We need to un-hide the matching end line 4. Also work backwards and if there’s a mis-matched keyword, show it too
Foo::Bar = 1 ^^^^^^^^^^^^
Foo::Foo, Bar::Bar = 1 ^^^^^^^^ ^^^^^^^^