When argument hash
is not given, returns a new hash whose keys are the distinct elements in self
; each integer value is the count of occurrences of each element:
%w[a b c b c a c b].tally # => {"a"=>2, "b"=>3, "c"=>3}
When argument hash
is given, returns hash
, possibly augmented; for each element ele
in self
:
Adds it as a key with a zero value if that key does not already exist:
hash[ele] = 0 unless hash.include?(ele)
Increments the value of key ele
:
hash[ele] += 1
This is useful for accumulating tallies across multiple enumerables:
h = {} # => {} %w[a c d b c a].tally(h) # => {"a"=>2, "c"=>2, "d"=>1, "b"=>1} %w[b a z].tally(h) # => {"a"=>3, "c"=>2, "d"=>1, "b"=>2, "z"=>1} %w[b a m].tally(h) # => {"a"=>4, "c"=>2, "d"=>1, "b"=>3, "z"=>1, "m"=>1}
The key to be added or found for an element depends on the class of self
; see Enumerable in Ruby Classes.
Examples:
Array
(and certain array-like classes): the key is the element (as above).
Hash
(and certain hash-like classes): the key is the 2-element array formed from the key-value pair:
h = {} # => {} {foo: 'a', bar: 'b'}.tally(h) # => {[:foo, "a"]=>1, [:bar, "b"]=>1} {foo: 'c', bar: 'd'}.tally(h) # => {[:foo, "a"]=>1, [:bar, "b"]=>1, [:foo, "c"]=>1, [:bar, "d"]=>1} {foo: 'a', bar: 'b'}.tally(h) # => {[:foo, "a"]=>2, [:bar, "b"]=>2, [:foo, "c"]=>1, [:bar, "d"]=>1} {foo: 'c', bar: 'd'}.tally(h) # => {[:foo, "a"]=>2, [:bar, "b"]=>2, [:foo, "c"]=>2, [:bar, "d"]=>2}
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.
References:
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.
References:
Response class for Variant Also Negotiates
responses (status code 506).
Transparent content negotiation for the request results in a circular reference.
References:
Ripper.lex
is not guaranteed to lex the entire source document
This class guarantees the whole document is lex-ed by iteratively lexing the document where ripper stopped.
Prism
likely doesn’t have the same problem. Once ripper support is removed we can likely reduce the complexity here if not remove the whole concept.
Example usage:
lex = LexAll.new(source: source) lex.each do |value| puts value.line end