A generic error class raised when an invalid operation is attempted. Kernel#raise
will raise a RuntimeError
if no Exception
class is specified.
raise "ouch"
raises the exception:
RuntimeError: ouch
Raised when throw
is called with a tag which does not have corresponding catch
block.
throw "foo", "bar"
raises the exception:
UncaughtThrowError: uncaught throw "foo"
A concrete implementation of Delegator
, this class provides the means to delegate all supported method calls to the object passed into the constructor and even to change the object being delegated to at a later time with __setobj__
.
class User def born_on Date.new(1989, 9, 10) end end require 'delegate' class UserDecorator < SimpleDelegator def birth_year born_on.year end end decorated_user = UserDecorator.new(User.new) decorated_user.birth_year #=> 1989 decorated_user.__getobj__ #=> #<User: ...>
A SimpleDelegator
instance can take advantage of the fact that SimpleDelegator
is a subclass of Delegator
to call super
to have methods called on the object being delegated to.
class SuperArray < SimpleDelegator def [](*args) super + 1 end end SuperArray.new([1])[0] #=> 2
Here’s a simple example that takes advantage of the fact that SimpleDelegator’s delegation object can be changed at any time.
class Stats def initialize @source = SimpleDelegator.new([]) end def stats(records) @source.__setobj__(records) "Elements: #{@source.size}\n" + " Non-Nil: #{@source.compact.size}\n" + " Unique: #{@source.uniq.size}\n" end end s = Stats.new puts s.stats(%w{James Edward Gray II}) puts puts s.stats([1, 2, 3, nil, 4, 5, 1, 2])
Prints:
Elements: 4 Non-Nil: 4 Unique: 4 Elements: 8 Non-Nil: 7 Unique: 6
SingleForwardable
can be used to setup delegation at the object level as well.
printer = String.new printer.extend SingleForwardable # prepare object for delegation printer.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts() printer.puts "Howdy!"
Also, SingleForwardable
can be used to set up delegation for a Class
or Module
.
class Implementation def self.service puts "serviced!" end end module Facade extend SingleForwardable def_delegator :Implementation, :service end Facade.service #=> serviced!
If you want to use both Forwardable
and SingleForwardable
, you can use methods def_instance_delegator and def_single_delegator
, etc.
Potentially raised when a specification is validated.
The InstructionSequence
class represents a compiled sequence of instructions for the Virtual Machine used in MRI. Not all implementations of Ruby may implement this class, and for the implementations that implement it, the methods defined and behavior of the methods can change in any version.
With it, you can get a handle to the instructions that make up a method or a proc, compile strings of Ruby code down to VM instructions, and disassemble instruction sequences to strings for easy inspection. It is mostly useful if you want to learn how YARV works, but it also lets you control various settings for the Ruby iseq compiler.
You can find the source for the VM instructions in insns.def
in the Ruby source.
The instruction sequence results will almost certainly change as Ruby changes, so example output in this documentation may be different from what you see.
Of course, this class is MRI specific.
Response class for Non-Authoritative Information
responses (status code 203).
The Non-Authoritative Information
response indicates that the server is a transforming proxy (such as a Web accelerator) that received a 200 OK response from its origin, and is returning a modified version of the origin’s response.
References:
Mixin methods for –version and –platform Gem::Command
options.
Represents a module declaration involving the ‘module` keyword.
module Foo end ^^^^^^^^^^^^^^
A pointer to a C union
Parent class for redirection (3xx) HTTP
response classes.
A redirection response indicates the client must take additional action to complete the request.
References:
Response class for Proxy Authentication Required
responses (status code 407).
The client must first authenticate itself with the proxy.
References:
Response class for Precondition Required
responses (status code 428).
The origin server requires the request to be conditional.
References:
Response class for Network Authentication Required
responses (status code 511).
The client needs to authenticate to gain network access.
References:
Raised by Gem::Resolver
when a Gem::Dependency::Conflict reaches the toplevel. Indicates which dependencies were incompatible through conflict
and conflicting_dependencies
Raised when attempting to uninstall a gem that isn’t in GEM_HOME.
Raised by the DependencyInstaller when a specific gem cannot be found
UserInteraction
allows RubyGems to interact with the user through standard methods that can be replaced with more-specific UI methods for different displays.
Since UserInteraction
dispatches to a concrete UI class you may need to reference other classes for specific behavior such as Gem::ConsoleUI
or Gem::SilentUI
.
Example:
class X include Gem::UserInteraction def get_answer n = ask("What is the meaning of life?") end end
A base class for objects representing a C union
ResolutionError
is the error class for socket name resolution.