Results for: "Pathname"

See as_json.

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.

Returns true if the arguments define a valid ordinal date, false otherwise:

Date.valid_date?(2001, 2, 3)  # => true
Date.valid_date?(2001, 2, 29) # => false
Date.valid_date?(2001, 2, -1) # => true

See argument start.

Related: Date.jd, Date.new.

Returns true if the arguments define a valid commercial date, false otherwise:

Date.valid_commercial?(2001, 5, 6) # => true
Date.valid_commercial?(2001, 5, 8) # => false

See Date.commercial.

See argument start.

Related: Date.jd, Date.commercial.

Equivalent to >> with argument n.

Equivalent to << with argument n.

Returns a new Time object with the same value as self; if self is a Julian date, derives its Gregorian date for conversion to the Time object:

Date.new(2001, 2, 3).to_time               # => 2001-02-03 00:00:00 -0600
Date.new(2001, 2, 3, Date::JULIAN).to_time # => 2001-02-16 00:00:00 -0600

Returns self.

See as_json.

Returns a Time object which denotes self.

Returns a Date object which denotes self.

See as_json.

Returns self.

Returns a Date object which denotes self.

See as_json.

Copies from the given src to the given dst, returning the number of bytes copied.

The examples here use file t.txt as source:

File.read('t.txt')
# => "First line\nSecond line\n\nThird line\nFourth line\n"
File.read('t.txt').size # => 47

If only arguments src and dst are given, the entire source stream is copied:

# Paths.
IO.copy_stream('t.txt', 't.tmp')  # => 47

# IOs (recall that a File is also an IO).
src_io = File.open('t.txt', 'r') # => #<File:t.txt>
dst_io = File.open('t.tmp', 'w') # => #<File:t.tmp>
IO.copy_stream(src_io, dst_io)   # => 47
src_io.close
dst_io.close

With argument src_length a non-negative integer, no more than that many bytes are copied:

IO.copy_stream('t.txt', 't.tmp', 10) # => 10
File.read('t.tmp')                   # => "First line"

With argument src_offset also given, the source stream is read beginning at that offset:

IO.copy_stream('t.txt', 't.tmp', 11, 11) # => 11
IO.read('t.tmp')                         # => "Second line"

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 as_json.

Yields all attributes (as symbols) along with the corresponding values or returns an enumerator if no block is given.

require "ostruct"
data = OpenStruct.new("country" => "Australia", :capital => "Canberra")
data.each_pair.to_a   # => [[:country, "Australia"], [:capital, "Canberra"]]

See as_json.

See as_json.

With no argument, returns the value of $!, which is the result of the most recent pattern match (see Regexp global variables):

/c(.)t/ =~ 'cat'  # => 0
Regexp.last_match # => #<MatchData "cat" 1:"a">
/a/ =~ 'foo'      # => nil
Regexp.last_match # => nil

With non-negative integer argument n, returns the _n_th field in the matchdata, if any, or nil if none:

/c(.)t/ =~ 'cat'     # => 0
Regexp.last_match(0) # => "cat"
Regexp.last_match(1) # => "a"
Regexp.last_match(2) # => nil

With negative integer argument n, counts backwards from the last field:

Regexp.last_match(-1)       # => "a"

With string or symbol argument name, returns the string value for the named capture, if any:

/(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ 'var = val'
Regexp.last_match        # => #<MatchData "var = val" lhs:"var"rhs:"val">
Regexp.last_match(:lhs)  # => "var"
Regexp.last_match('rhs') # => "val"
Regexp.last_match('foo') # Raises IndexError.

Returns true if matching against re can be done in linear time to the input string.

Regexp.linear_time?(/re/) # => true

Note that this is a property of the ruby interpreter, not of the argument regular expression. Identical regexp can or cannot run in linear time depending on your ruby binary. Neither forward nor backward compatibility is guaranteed about the return value of this method. Our current algorithm is (*1) but this is subject to change in the future. Alternative implementations can also behave differently. They might always return false for everything.

(*1): doi.org/10.1109/SP40001.2021.00032

See as_json.

Search took: 5ms  ·  Total Results: 2920