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 true for IPv4-compatible IPv6 address (::/80). It returns false otherwise.
Returns the socket path as a string.
Addrinfo.unix("/tmp/sock").unix_path #=> "/tmp/sock"
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}
Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self
is set to obj while the code is executing, giving the code access to obj’s instance variables and private methods.
When instance_eval
is given a block, obj is also passed in as the block’s only argument.
When instance_eval
is given a String
, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.
class KlassWithSecret def initialize @secret = 99 end private def the_secret "Ssssh! The secret is #{@secret}." end end k = KlassWithSecret.new k.instance_eval { @secret } #=> 99 k.instance_eval { the_secret } #=> "Ssssh! The secret is 99." k.instance_eval {|obj| obj == self } #=> true
Executes the given block within the context of the receiver (obj). In order to set the context, the variable self
is set to obj while the code is executing, giving the code access to obj’s instance variables. Arguments are passed as block parameters.
class KlassWithSecret def initialize @secret = 99 end end k = KlassWithSecret.new k.instance_exec(5) {|x| @secret+x } #=> 104
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]
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 true if the ipaddr is an IPv4-compatible IPv6 address.
Returns a new ipaddr built by converting the native IPv4 address into an IPv4-compatible IPv6 address.
Returns the Ruby source filename and line number of the binding object.
Creates an option from the given parameters params
. See Parameters for New Options.
The block, if given, is the handler for the created option. When the option is encountered during command-line parsing, the block is called with the argument given for the option, if any. See Option Handlers.