Equivalent to self.to_s.end_with?
; see String#end_with?
.
Returns true if this class can be used to create an instance from a serialised JSON
string. The class has to implement a class method json_create that expects a hash as first parameter. The hash should include the required data.
Returns the object for which the receiver is the singleton class.
Raises an TypeError
if the class is not a singleton class.
class Foo; end Foo.singleton_class.attached_object #=> Foo Foo.attached_object #=> TypeError: `Foo' is not a singleton class Foo.new.singleton_class.attached_object #=> #<Foo:0x000000010491a370> TrueClass.attached_object #=> TypeError: `TrueClass' is not a singleton class NilClass.attached_object #=> TypeError: `NilClass' is not a singleton class
creates an Addrinfo
object from the arguments.
The arguments are interpreted as similar to self.
Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80) #=> #<Addrinfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)> Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2") #=> #<Addrinfo: /tmp/sock2 SOCK_STREAM>
creates a new Socket
connected to the address of local_addrinfo
.
If local_addrinfo is nil, the address of the socket is not bound.
The timeout specify the seconds for timeout. Errno::ETIMEDOUT is raised when timeout occur.
If a block is given the created socket is yielded for each address.
Returns the IP address and port number as 2-element array.
Addrinfo.tcp("127.0.0.1", 80).ip_unpack #=> ["127.0.0.1", 80] Addrinfo.tcp("::1", 80).ip_unpack #=> ["::1", 80]
Returns true for IPv4 private address (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16). It returns false otherwise.
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
.
Returns the size (in bytes) of the matched substring from the most recent match [match attempt] if it was successful, or nil
otherwise; see [Basic Matched Values]:
scanner = StringScanner.new('foobarbaz') scanner.matched_size # => nil pos = 3 scanner.exist?(/baz/) # => 9 scanner.matched_size # => 3 scanner.exist?(/nope/) # => nil scanner.matched_size # => nil
Returns the substring that precedes the matched substring from the most recent match attempt if it was successful, or nil
otherwise; see [Basic Match Values]:
scanner = StringScanner.new('foobarbaz') scanner.pre_match # => nil scanner.pos = 3 scanner.exist?(/baz/) # => 6 scanner.pre_match # => "foobar" # Substring of entire string, not just target string. scanner.exist?(/nope/) # => nil scanner.pre_match # => nil
Returns the substring that follows the matched substring from the most recent match attempt if it was successful, or nil
otherwise; see [Basic Match Values]:
scanner = StringScanner.new('foobarbaz') scanner.post_match # => nil scanner.pos = 3 scanner.match?(/bar/) # => 3 scanner.post_match # => "baz" scanner.match?(/nope/) # => nil scanner.post_match # => nil
Returns an array of captured substrings, or nil
of none.
For each specifier
, the returned substring is [specifier]
; see []
.
scanner = StringScanner.new('Fri Dec 12 1975 14:39') pattern = /(?<wday>\w+) (?<month>\w+) (?<day>\d+) / scanner.match?(pattern) scanner.values_at(*0..3) # => ["Fri Dec 12 ", "Fri", "Dec", "12"] scanner.values_at(*%i[wday month day]) # => ["Fri", "Dec", "12"]
Creates GUID.
WIN32OLE.create_guid # => {1CB530F1-F6B1-404D-BCE6-1959BF91F4A8}
Calls the given block with each key-value pair; returns self
:
h = {foo: 0, bar: 1, baz: 2} h.each_pair {|key, value| puts "#{key}: #{value}"} # => {:foo=>0, :bar=>1, :baz=>2}
Output:
foo: 0 bar: 1 baz: 2
Returns a new Enumerator
if no block given:
h = {foo: 0, bar: 1, baz: 2} e = h.each_pair # => #<Enumerator: {:foo=>0, :bar=>1, :baz=>2}:each_pair> h1 = e.each {|key, value| puts "#{key}: #{value}"} h1 # => {:foo=>0, :bar=>1, :baz=>2}
Output:
foo: 0 bar: 1 baz: 2
Returns a new Array
containing values for the given keys
:
h = {foo: 0, bar: 1, baz: 2} h.values_at(:baz, :foo) # => [2, 0]
The default values are returned for any keys that are not found:
h.values_at(:hello, :foo) # => [nil, 0]
Yields each environment variable name and its value as a 2-element Array:
h = {} ENV.each_pair { |name, value| h[name] = value } # => ENV h # => {"bar"=>"1", "foo"=>"0"}
Returns an Enumerator
if no block given:
h = {} e = ENV.each_pair # => #<Enumerator: {"bar"=>"1", "foo"=>"0"}:each_pair> e.each { |name, value| h[name] = value } # => ENV h # => {"bar"=>"1", "foo"=>"0"}
Returns an Array
containing the environment variable values associated with the given names:
ENV.replace('foo' => '0', 'bar' => '1', 'baz' => '2') ENV.values_at('foo', 'baz') # => ["0", "2"]
Returns nil
in the Array
for each name that is not an ENV
name:
ENV.values_at('foo', 'bat', 'bar', 'bam') # => ["0", nil, "1", nil]
Returns an empty Array
if no names given.
Raises an exception if any name is invalid. See Invalid Names and Values.
Returns the external encoding for files read from ARGF
as an Encoding
object. The external encoding is the encoding of the text as stored in a file. Contrast with ARGF.internal_encoding
, which is the encoding used to represent this text within Ruby.
To set the external encoding use ARGF.set_encoding
.
For example:
ARGF.external_encoding #=> #<Encoding:UTF-8>
Returns the internal encoding for strings read from ARGF
as an Encoding
object.
If ARGF.set_encoding
has been called with two encoding names, the second is returned. Otherwise, if Encoding.default_external
has been set, that value is returned. Failing that, if a default external encoding was specified on the command-line, that value is used. If the encoding is unknown, nil
is returned.
Returns a string for DNS reverse lookup compatible with RFC3172.
Returns the Ruby source filename and line number of the binding object.
Adjust the log level during the block execution for the current Fiber
only
logger.with_level(:debug) do logger.debug { "Hello" } end