Results for: "match"

Returns the date-time format; see datetime_format=.

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.

Sends a PATCH request to the server; returns an instance of a subclass of Net::HTTPResponse.

The request is based on the Net::HTTP::Patch object created from string path, string data, and initial headers hash initheader.

With a block given, calls the block with the response body:

data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
http = Net::HTTP.new(hostname)
http.patch('/todos/1', data) do |res|
  p res
end # => #<Net::HTTPOK 200 OK readbody=true>

Output:

"{\n  \"userId\": 1,\n  \"id\": 1,\n  \"title\": \"delectus aut autem\",\n  \"completed\": false,\n  \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\"\n}"

With no block given, simply returns the response object:

http.patch('/todos/1', data) # => #<Net::HTTPCreated 201 Created readbody=true>

Sends a PROPPATCH request to the server; returns an instance of a subclass of Net::HTTPResponse.

The request is based on the Net::HTTP::Proppatch object created from string path, string body, and initial headers hash initheader.

data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
http = Net::HTTP.new(hostname)
http.proppatch('/todos/1', data)

Returns the element at offset index.

With the single Integer argument index, returns the element at offset index:

a = [:foo, 'bar', 2]
a.fetch(1) # => "bar"

If index is negative, counts from the end of the array:

a = [:foo, 'bar', 2]
a.fetch(-1) # => 2
a.fetch(-2) # => "bar"

With arguments index and default_value, returns the element at offset index if index is in range, otherwise returns default_value:

a = [:foo, 'bar', 2]
a.fetch(1, nil) # => "bar"

With argument index and a block, returns the element at offset index if index is in range (and the block is not called); otherwise calls the block with index and returns its return value:

a = [:foo, 'bar', 2]
a.fetch(1) {|index| raise 'Cannot happen' } # => "bar"
a.fetch(50) {|index| "Value for #{index}" } # => "Value for 50"

Returns a hash of values parsed from string, which should be a valid XML date format:

d = Date.new(2001, 2, 3)
s = d.xmlschema    # => "2001-02-03"
Date._xmlschema(s) # => {:year=>2001, :mon=>2, :mday=>3}

See argument limit.

Related: Date.xmlschema (returns a Date object).

Returns a new Date object with values parsed from string, which should be a valid XML date format:

d = Date.new(2001, 2, 3)
s = d.xmlschema   # => "2001-02-03"
Date.xmlschema(s) # => #<Date: 2001-02-03>

See:

Related: Date._xmlschema (returns a hash).

Equivalent to strftime with argument '%Y-%m-%d' (or its shorthand form '%F');

Date.new(2001, 2, 3).iso8601 # => "2001-02-03"

Creates a new DateTime object by parsing from a string according to some typical XML Schema formats.

DateTime.xmlschema('2001-02-03T04:05:06+07:00')
                          #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>

Raise an ArgumentError when the string length is longer than limit. You can stop this check by passing limit: nil, but note that it may take a long time to parse.

This method is equivalent to strftime(‘%FT%T%:z’). The optional argument n is the number of digits for fractional seconds.

DateTime.parse('2001-02-03T04:05:06.123456789+07:00').iso8601(9)
                          #=> "2001-02-03T04:05:06.123456789+07:00"

Parses time as a dateTime defined by the XML Schema and converts it to a Time object. The format is a restricted version of the format defined by ISO 8601.

ArgumentError is raised if time is not compliant with the format or if the Time class cannot represent the specified time.

See xmlschema for more information on this format.

require 'time'

Time.xmlschema("2011-10-05T22:26:12-04:00")
#=> 2011-10-05 22:26:12-04:00

You must require ‘time’ to use this method.

Returns a string which represents the time as a dateTime defined by XML Schema:

CCYY-MM-DDThh:mm:ssTZD
CCYY-MM-DDThh:mm:ss.sssTZD

where TZD is Z or [+-]hh:mm.

If self is a UTC time, Z is used as TZD. [+-]hh:mm is used otherwise.

fraction_digits specifies a number of digits to use for fractional seconds. Its default value is 0.

require 'time'

t = Time.now
t.iso8601  # => "2011-10-05T22:26:12-04:00"

You must require ‘time’ to use this method.

Reads and returns a character in raw mode.

See IO#raw for details on the parameters.

You must require ‘io/console’ to use this method.

Scans one character and returns it. This method is multibyte character sensitive.

s = StringScanner.new("ab")
s.getch           # => "a"
s.getch           # => "b"
s.getch           # => nil

s = StringScanner.new("\244\242".force_encoding("euc-jp"))
s.getch           # => "\x{A4A2}"   # Japanese hira-kana "A" in EUC-JP
s.getch           # => nil

Returns the value for the given key, if found.

h = {foo: 0, bar: 1, baz: 2}
h.fetch(:bar) # => 1

If key is not found and no block was given, returns default_value:

{}.fetch(:nosuch, :default) # => :default

If key is not found and a block was given, yields key to the block and returns the block’s return value:

{}.fetch(:nosuch) {|key| "No key #{key}"} # => "No key nosuch"

Raises KeyError if neither default_value nor a block was given.

Note that this method does not use the values of either default or default_proc.

If name is the name of an environment variable, returns its value:

ENV['foo'] = '0'
ENV.fetch('foo') # => '0'

Otherwise if a block is given (but not a default value), yields name to the block and returns the block’s return value:

ENV.fetch('foo') { |name| :need_not_return_a_string } # => :need_not_return_a_string

Otherwise if a default value is given (but not a block), returns the default value:

ENV.delete('foo')
ENV.fetch('foo', :default_need_not_be_a_string) # => :default_need_not_be_a_string

If the environment variable does not exist and both default and block are given, issues a warning (“warning: block supersedes default value argument”), yields name to the block, and returns the block’s return value:

ENV.fetch('foo', :default) { |name| :block_return } # => :block_return

Raises KeyError if name is valid, but not found, and neither default value nor block is given:

ENV.fetch('foo') # Raises KeyError (key not found: "foo")

Raises an exception if name is invalid. See Invalid Names and Values.

This is a convenience method which is same as follows:

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

Like [], except that it accepts a default value for the store. If the key does not exist:

Raises an exception if called outside a transaction block.

Returns a fiber-local for the given key. If the key can’t be found, there are several options: With no other arguments, it will raise a KeyError exception; if default is given, then that will be returned; if the optional code block is specified, then that will be run and its result returned. See Thread#[] and Hash#fetch.

Returns the string resulting from formatting objects into format_string.

For details on format_string, see Format Specifications.

Invokes the block with a Benchmark::Report object, which may be used to collect and report on the results of individual benchmark tests. Reserves label_width leading spaces for labels on each line. Prints caption at the top of the report, and uses format to format each line. (Note: caption must contain a terminating newline character, see the default Benchmark::Tms::CAPTION for an example.)

Returns an array of Benchmark::Tms objects.

If the block returns an array of Benchmark::Tms objects, these will be used to format additional lines of output. If labels parameter are given, these are used to label these extra lines.

Note: Other methods provide a simpler interface to this one, and are suitable for nearly all benchmarking requirements. See the examples in Benchmark, and the bm and bmbm methods.

Example:

require 'benchmark'
include Benchmark          # we need the CAPTION and FORMAT constants

n = 5000000
Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
  tf = x.report("for:")   { for i in 1..n; a = "1"; end }
  tt = x.report("times:") { n.times do   ; a = "1"; end }
  tu = x.report("upto:")  { 1.upto(n) do ; a = "1"; end }
  [tf+tt+tu, (tf+tt+tu)/3]
end

Generates:

              user     system      total        real
for:      0.970000   0.000000   0.970000 (  0.970493)
times:    0.990000   0.000000   0.990000 (  0.989542)
upto:     0.970000   0.000000   0.970000 (  0.972854)
>total:   2.930000   0.000000   2.930000 (  2.932889)
>avg:     0.976667   0.000000   0.976667 (  0.977630)

Invokes the block with a Benchmark::Report object, which may be used to collect and report on the results of individual benchmark tests. Reserves label_width leading spaces for labels on each line. Prints caption at the top of the report, and uses format to format each line. (Note: caption must contain a terminating newline character, see the default Benchmark::Tms::CAPTION for an example.)

Returns an array of Benchmark::Tms objects.

If the block returns an array of Benchmark::Tms objects, these will be used to format additional lines of output. If labels parameter are given, these are used to label these extra lines.

Note: Other methods provide a simpler interface to this one, and are suitable for nearly all benchmarking requirements. See the examples in Benchmark, and the bm and bmbm methods.

Example:

require 'benchmark'
include Benchmark          # we need the CAPTION and FORMAT constants

n = 5000000
Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
  tf = x.report("for:")   { for i in 1..n; a = "1"; end }
  tt = x.report("times:") { n.times do   ; a = "1"; end }
  tu = x.report("upto:")  { 1.upto(n) do ; a = "1"; end }
  [tf+tt+tu, (tf+tt+tu)/3]
end

Generates:

              user     system      total        real
for:      0.970000   0.000000   0.970000 (  0.970493)
times:    0.990000   0.000000   0.990000 (  0.989542)
upto:     0.970000   0.000000   0.970000 (  0.972854)
>total:   2.930000   0.000000   2.930000 (  2.932889)
>avg:     0.976667   0.000000   0.976667 (  0.977630)

Returns the currently set formatter. By default, it is set to DidYouMean::Formatter.

Updates the primary formatter used to format the suggestions.

No documentation available
Search took: 11ms  ·  Total Results: 2422