Represents writing to an instance variable in a context that doesn’t have an explicit value.
@foo, @bar = baz ^^^^ ^^^^
Represents a string literal that contains interpolation.
"foo #{bar} baz" ^^^^^^^^^^^^^^^^
Represents an xstring literal that contains interpolation.
`foo #{bar} baz` ^^^^^^^^^^^^^^^^
Represents reading a local variable. Note that this requires that a local variable of the same name has already been written to in the same scope, otherwise it is parsed as a method call.
foo ^^^
Represents writing to a local variable in a context that doesn’t have an explicit value.
foo, bar = baz ^^^ ^^^
Represents writing local variables using a regular expression match with named capture groups.
/(?<foo>bar)/ =~ baz ^^^^^^^^^^^^^^^^^^^^
Represents a write to a multi-target expression.
a, b, c = 1, 2, 3 ^^^^^^^^^^^^^^^^^
Represents the use of the ‘^` operator for pinning a variable in a pattern matching expression.
foo in ^bar ^^^^
Represents the use of the ‘__ENCODING__` keyword.
__ENCODING__ ^^^^^^^^^^^^
Represents a string literal, a string contained within a ‘%w` list, or plain string content within an interpolated string.
"foo" ^^^^^ %w[foo] ^^^ "foo #{bar} baz" ^^^^ ^^^^
This represents a source of Ruby code that has been parsed. It is used in conjunction with locations to allow them to resolve line numbers and source ranges.
Specialized version of Prism::Source
for source code that includes ASCII characters only. This class is used to apply performance optimizations that cannot be applied to sources that include multibyte characters. Sources that include multibyte characters are represented by the Prism::Source
class.
An error that indicates we weren’t able to fetch some data from a source
Represents an error communicating via HTTP.
Raised by Gem::Validator
when something is not right in a gem.
Raised by Gem::WebauthnListener when an error occurs during security device verification.
A Source
knows how to list and fetch gems from a RubyGems marshal index.
There are other Source
subclasses for installed gems, local gems, the bundler dependency API and so-forth.
The SourceList
represents the sources rubygems has been configured to use. A source may be created from an array of sources:
Gem::SourceList.from %w[https://rubygems.example https://internal.example]
Or by adding them:
sources = Gem::SourceList.new sources << 'https://rubygems.example'
The most common way to get a SourceList
is Gem.sources
.
Turns a “invalid block(s)” into useful context
There are three main phases in the algorithm:
Sanitize/format input source
Search for invalid blocks
Format invalid blocks into something meaninful
This class handles the third part.
The algorithm is very good at capturing all of a syntax error in a single block in number 2, however the results can contain ambiguities. Humans are good at pattern matching and filtering and can mentally remove extraneous data, but they can’t add extra data that’s not present.
In the case of known ambiguious cases, this class adds context back to the ambiguity so the programmer has full information.
Beyond handling these ambiguities, it also captures surrounding code context information:
puts block.to_s # => "def bark" context = CaptureCodeContext.new( blocks: block, code_lines: code_lines ) lines = context.call.map(&:original) puts lines.join # => class Dog def bark end
Acts like a StringIO
with reduced API, but without having to require that class.