Results for: "minmax"

Returns “ARGF”.

Returns a new ipaddr built by masking IP address with the given prefixlen/netmask. (e.g. 8, 64, “255.255.255.0”, etc.)

Returns true if the given ipaddr is in the range.

e.g.:

require 'ipaddr'
net1 = IPAddr.new("192.168.2.0/24")
net2 = IPAddr.new("192.168.2.100")
net3 = IPAddr.new("192.168.3.0")
net4 = IPAddr.new("192.168.2.0/16")
p net1.include?(net2)     #=> true
p net1.include?(net3)     #=> false
p net1.include?(net4)     #=> false
p net4.include?(net1)     #=> true

Returns a string containing a human-readable representation of the ipaddr. (“#<IPAddr: family:address/mask>”)

Returns the netmask in string format e.g. 255.255.0.0

Set current netmask to given mask.

Returns true if the log level allows entries with severity Logger::INFO to be written, false otherwise. See Log Level.

Sets the log level to Logger::INFO. See Log Level.

Equivalent to calling add with severity Logger::INFO.

Returns an incremented value of default according to arg.

See self.inc

Puts option summary into to and returns to. Yields each line if a block is given.

to

Output destination, which must have method <<. Defaults to [].

width

Width of left side, defaults to @summary_width.

max

Maximum length allowed for left side, defaults to width - 1.

indent

Indentation, defaults to @summary_indent.

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.

Parses environment variable env or its uppercase with splitting like a shell.

env defaults to the basename of the program.

Defines a new Data class.

measure = Data.define(:amount, :unit)
#=> #<Class:0x00007f70c6868498>
measure.new(1, 'km')
#=> #<data amount=1, unit="km">

# It you store the new class in the constant, it will
# affect #inspect and will be more natural to use:
Measure = Data.define(:amount, :unit)
#=> Measure
Measure.new(1, 'km')
#=> #<data Measure amount=1, unit="km">

Note that member-less Data is acceptable and might be a useful technique for defining several homogenous data classes, like

class HTTPFetcher
  Response = Data.define(:body)
  NotFound = Data.define
  # ... implementation
end

Now, different kinds of responses from HTTPFetcher would have consistent representation:

#<data HTTPFetcher::Response body="<html...">
#<data HTTPFetcher::NotFound>

And are convenient to use in pattern matching:

case fetcher.get(url)
in HTTPFetcher::Response(body)
  # process body variable
in HTTPFetcher::NotFound
  # handle not found case
end

Returns a string representation of self:

Measure = Data.define(:amount, :unit)

distance = Measure[10, 'km']

p distance  # uses #inspect underneath
#<data Measure amount=10, unit="km">

puts distance  # uses #to_s underneath, same representation
#<data Measure amount=10, unit="km">

Returns the offset (in bytes) of the beginning of the specified match.

When non-negative integer argument n is given, returns the offset of the beginning of the nth match:

m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m[0]       # => "HX1138"
m.bytebegin(0) # => 1
m[3]       # => "113"
m.bytebegin(3) # => 3

m = /(т)(е)(с)/.match('тест')
# => #<MatchData "тес" 1:"т" 2:"е" 3:"с">
m[0]       # => "тес"
m.bytebegin(0) # => 0
m[3]       # => "с"
m.bytebegin(3) # => 4

When string or symbol argument name is given, returns the offset of the beginning for the named match:

m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
# => #<MatchData "hog" foo:"h" bar:"g">
m[:foo]        # => "h"
m.bytebegin('foo') # => 0
m[:bar]        # => "g"
m.bytebegin(:bar)  # => 2

Related: MatchData#byteend, MatchData#byteoffset.

Returns the offset (in characters) of the beginning of the specified match.

When non-negative integer argument n is given, returns the offset of the beginning of the nth match:

m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m[0]       # => "HX1138"
m.begin(0) # => 1
m[3]       # => "113"
m.begin(3) # => 3

m = /(т)(е)(с)/.match('тест')
# => #<MatchData "тес" 1:"т" 2:"е" 3:"с">
m[0]       # => "тес"
m.begin(0) # => 0
m[3]       # => "с"
m.begin(3) # => 2

When string or symbol argument name is given, returns the offset of the beginning for the named match:

m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
# => #<MatchData "hog" foo:"h" bar:"g">
m[:foo]        # => "h"
m.begin('foo') # => 0
m[:bar]        # => "g"
m.begin(:bar)  # => 2

Related: MatchData#end, MatchData#offset, MatchData#byteoffset.

Returns the matched substring corresponding to the given argument.

When non-negative argument n is given, returns the matched substring for the nth match:

m = /(.)(.)(\d+)(\d)(\w)?/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8" 5:nil>
m.match(0) # => "HX1138"
m.match(4) # => "8"
m.match(5) # => nil

When string or symbol argument name is given, returns the matched substring for the given name:

m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
# => #<MatchData "hoge" foo:"h" bar:"ge">
m.match('foo') # => "h"
m.match(:bar)  # => "ge"

Returns a string representation of self:

m = /.$/.match("foo")
# => #<MatchData "o">
m.inspect # => "#<MatchData \"o\">"

m = /(.)(.)(.)/.match("foo")
# => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
m.inspect # => "#<MatchData \"foo\" 1:\"f\" 2:\"o\

m = /(.)(.)?(.)/.match("fo")
# => #<MatchData "fo" 1:"f" 2:nil 3:"o">
m.inspect # => "#<MatchData \"fo\" 1:\"f\" 2:nil 3:\"o\">"

Related: MatchData#to_s.

Returns the target string if it was frozen; otherwise, returns a frozen copy of the target string:

m = /(.)(.)(\d+)(\d)/.match("THX1138.")
# => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
m.string # => "THX1138."

This is a convenience method which is same as follows:

begin
  q = PrettyPrint.new(output, maxwidth, newline, &genspace)
  ...
  q.flush
  output
end

Exits the current transaction block, committing any changes specified in the transaction block.

Raises an exception if called outside a transaction block.

Unlinks (deletes) the file from the filesystem. One should always unlink the file after using it, as is explained in the “Explicit close” good practice section in the Tempfile overview:

file = Tempfile.new('foo')
begin
   # ...do something with file...
ensure
   file.close
   file.unlink   # deletes the temp file
end

On POSIX systems it’s possible to unlink a file before closing it. This practice is explained in detail in the Tempfile overview (section “Unlink after creation”); please refer there for more information.

However, unlink-before-close may not be supported on non-POSIX operating systems. Microsoft Windows is the most notable case: unlinking a non-closed file will result in an error, which this method will silently ignore. If you want to practice unlink-before-close whenever possible, then you should write code like this:

file = Tempfile.new('foo')
file.unlink   # On Windows this silently fails.
begin
   # ... do something with file ...
ensure
   file.close!   # Closes the file handle. If the file wasn't unlinked
                 # because #unlink failed, then this method will attempt
                 # to do so again.
end

Returns string 'true':

true.to_s # => "true"

TrueClass#inspect is an alias for TrueClass#to_s.

Search took: 9ms  ·  Total Results: 1823