Returns a hash containing the counts of equal elements:
Each key is an element of self
.
Each value is the number elements equal to that key.
With no argument:
%w[a b c b c a c b].tally # => {"a"=>2, "b"=>3, "c"=>3}
With a hash argument, that hash is used for the tally (instead of a new hash), and is returned; this may be useful for accumulating tallies across multiple enumerables:
hash = {} hash = %w[a c d b c a].tally(hash) hash # => {"a"=>2, "c"=>2, "d"=>1, "b"=>1} hash = %w[b a z].tally(hash) hash # => {"a"=>3, "c"=>2, "d"=>1, "b"=>2, "z"=>1} hash = %w[b a m].tally(hash) hash # => {"a"=>4, "c"=>2, "d"=>1, "b"=>3, "z"=>1, "m"=> 1}
SystemCallError
is the base class for all low-level platform-dependent errors.
The errors available on the current platform are subclasses of SystemCallError
and are defined in the Errno
module.
File.open("does/not/exist")
raises the exception:
Errno::ENOENT: No such file or directory - does/not/exist
Helper methods for both Gem::Installer
and Gem::Uninstaller
Response class for Method Not Allowed
responses (status code 405).
The request method is not supported for the requested resource. See 405 Method Not Allowed.
Installs a gem along with all its dependencies from local and remote gems.
Raised when removing a gem with the uninstall command fails
The installer installs the files contained in the .gem into the Gem.home.
Gem::Installer
does the work of putting files in all the right places on the filesystem including unpacking the gem into its gem dir, installing the gemspec in the specifications dir, storing the cached gem in the cache dir, and installing either wrappers or symlinks for executables.
The installer invokes pre and post install hooks. Hooks can be added either through a rubygems_plugin.rb file in an installed gem or via a rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb file. See Gem.pre_install
and Gem.post_install
for details.
An Uninstaller
.
The uninstaller fires pre and post uninstall hooks. Hooks can be added either through a rubygems_plugin.rb file in an installed gem or via a rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb file. See Gem.pre_uninstall
and Gem.post_uninstall
for details.
Mixin methods for install and update options for Gem::Commands
Socket::AncillaryData
represents the ancillary data (control information) used by sendmsg and recvmsg system call. It contains socket family
, control message (cmsg) level
, cmsg type
and cmsg data
.
Response class for Not Acceptable
responses (status code 406).
The requested resource is capable of generating only content that not acceptable according to the Accept headers sent in the request. See 406 Not Acceptable.
Response class for Variant Also Negotiates
responses (status code 506).
Transparent content negotiation for the request results in a circular reference. See 506 Variant Also Negotiates.
Ripper.lex
is not guaranteed to lex the entire source document
lex = LexAll.new
(source: source) lex.each do |value|
puts value.line
end
Raised when a signal is received.
begin Process.kill('HUP',Process.pid) sleep # wait for receiver to handle signal sent by Process.kill rescue SignalException => e puts "received Exception #{e}" end
produces:
received Exception SIGHUP
The most standard error types are subclasses of StandardError
. A rescue clause without an explicit Exception
class will rescue all StandardErrors (and only those).
def foo raise "Oups" end foo rescue "Hello" #=> "Hello"
On the other hand:
require 'does/not/exist' rescue "Hi"
raises the exception:
LoadError: no such file to load -- does/not/exist
Raised when encountering Ruby code with an invalid syntax.
eval("1+1=2")
raises the exception:
SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end