Returns a Digest
subclass by name
require 'openssl' OpenSSL::Digest("MD5") # => OpenSSL::Digest::MD5 Digest("Foo") # => NameError: wrong constant name Foo
Disables garbage collection, returning true
if garbage collection was already disabled.
GC.disable #=> false GC.disable #=> true
Returns time stamp of the target
file if it exists and is newer than or equal to all of times
.
Returns a string usable in Dir.glob
to match all requirable paths for this spec.
Creates a new directory in the tar file name
with mode
Dispatches a single event for ‘node` to all registered listeners.
def dispatch_once
: (Node
) -> void
Calls the given block once for each key
, value
pair in the database.
Returns self
.
Iterates over keys and values. Note that unlike other collections, each
without block isn’t supported.
@api private
Calls the given block with each successive character from self
; returns self
:
'hello'.each_char {|char| print char, ' ' } print "\n" 'тест'.each_char {|char| print char, ' ' } print "\n" 'こんにちは'.each_char {|char| print char, ' ' } print "\n"
Output:
h e l l o т е с т こ ん に ち は
Returns an enumerator if no block is given.
Changes the encoding of self
to encoding
, which may be a string encoding name or an Encoding
object; returns self:
s = 'łał' s.bytes # => [197, 130, 97, 197, 130] s.encoding # => #<Encoding:UTF-8> s.force_encoding('ascii') # => "\xC5\x82a\xC5\x82" s.encoding # => #<Encoding:US-ASCII>
Does not change the underlying bytes:
s.bytes # => [197, 130, 97, 197, 130]
Makes the change even if the given encoding
is invalid for self
(as is the change above):
s.valid_encoding? # => false s.force_encoding(Encoding::UTF_8) # => "łał" s.valid_encoding? # => true
Returns true
if self
is encoded correctly, false
otherwise:
"\xc2\xa1".force_encoding("UTF-8").valid_encoding? # => true "\xc2".force_encoding("UTF-8").valid_encoding? # => false "\x80".force_encoding("UTF-8").valid_encoding? # => false
Returns true
if the arguments define a valid ordinal date, false
otherwise:
Date.valid_ordinal?(2001, 34) # => true Date.valid_ordinal?(2001, 366) # => false
See argument start.
Related: Date.jd
, Date.ordinal
.
Calls the given block with each character in the stream; returns self
. See Character IO.
f = File.new('t.rus') a = [] f.each_char {|c| a << c.ord } a # => [1090, 1077, 1089, 1090] f.close
Returns an Enumerator
if no block is given.
Related: IO#each_byte
, IO#each_codepoint
.
Returns the Encoding
object that represents the encoding of the stream, or nil
if the stream is in write mode and no encoding is specified.
See Encodings.
Returns the Encoding
object that represents the encoding of the internal string, if conversion is specified, or nil
otherwise.
See Encodings.
See Encodings.
Argument ext_enc
, if given, must be an Encoding
object or a String
with the encoding name; it is assigned as the encoding for the stream.
Argument int_enc
, if given, must be an Encoding
object or a String
with the encoding name; it is assigned as the encoding for the internal string.
Argument 'ext_enc:int_enc'
, if given, is a string containing two colon-separated encoding names; corresponding Encoding
objects are assigned as the external and internal encodings for the stream.
If the external encoding of a string is binary/ASCII-8BIT, the internal encoding of the string is set to nil, since no transcoding is needed.
Optional keyword arguments enc_opts
specify Encoding options.
Returns false
if self
is applicable to a string with any ASCII-compatible encoding; otherwise returns true
:
r = /a/ # => /a/ r.fixed_encoding? # => false r.match?("\u{6666} a") # => true r.match?("\xa1\xa2 a".force_encoding("euc-jp")) # => true r.match?("abc".force_encoding("euc-jp")) # => true r = /a/u # => /a/ r.fixed_encoding? # => true r.match?("\u{6666} a") # => true r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception. r.match?("abc".force_encoding("euc-jp")) # => true r = /\u{6666}/ # => /\u{6666}/ r.fixed_encoding? # => true r.encoding # => #<Encoding:UTF-8> r.match?("\u{6666} a") # => true r.match?("\xa1\xa2".force_encoding("euc-jp")) # Raises exception. r.match?("abc".force_encoding("euc-jp")) # => false
Iterates over the children of the directory (files and subdirectories, not recursive).
It yields Pathname
object for each child.
By default, the yielded pathnames will have enough information to access the files.
If you set with_directory
to false
, then the returned pathnames will contain the filename only.
Pathname("/usr/local").each_child {|f| p f } #=> #<Pathname:/usr/local/share> # #<Pathname:/usr/local/bin> # #<Pathname:/usr/local/games> # #<Pathname:/usr/local/lib> # #<Pathname:/usr/local/include> # #<Pathname:/usr/local/sbin> # #<Pathname:/usr/local/src> # #<Pathname:/usr/local/man> Pathname("/usr/local").each_child(false) {|f| p f } #=> #<Pathname:share> # #<Pathname:bin> # #<Pathname:games> # #<Pathname:lib> # #<Pathname:include> # #<Pathname:sbin> # #<Pathname:src> # #<Pathname:man>
Note that the results never contain the entries .
and ..
in the directory because they are not children.
With a block given, calls the block with each remaining character in the stream; see Character IO.
With no block given, returns an enumerator.
Returns the Encoding
object that represents the encoding of the file. If the stream is write mode and no encoding is specified, returns nil
.
Returns the Encoding
of the internal string if conversion is specified. Otherwise returns nil
.
Specify the encoding of the StringIO
as ext_enc. Use the default external encoding if ext_enc is nil. 2nd argument int_enc and optional hash opt argument are ignored; they are for API compatibility to IO
.