Results for: "Pathname"

Like Time.utc, except that the returned Time object has the local timezone, not the UTC timezone:

# With seven arguments.
Time.local(0, 1, 2, 3, 4, 5, 6)
# => 0000-01-02 03:04:05.000006 -0600
# With exactly ten arguments.
Time.local(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
# => 0005-04-03 02:01:00 -0600

Returns a new Time object based on the given arguments.

Required argument time may be either of:

Examples:

t = Time.new(2000, 12, 31, 23, 59, 59) # => 2000-12-31 23:59:59 -0600
secs = t.to_i                          # => 978328799
Time.at(secs)                          # => 2000-12-31 23:59:59 -0600
Time.at(secs + 0.5)                    # => 2000-12-31 23:59:59.5 -0600
Time.at(1000000000)                    # => 2001-09-08 20:46:40 -0500
Time.at(0)                             # => 1969-12-31 18:00:00 -0600
Time.at(-1000000000)                   # => 1938-04-24 17:13:20 -0500

Optional numeric argument subsec and optional symbol argument units work together to specify subseconds for the returned time; argument units specifies the units for subsec:

Optional keyword argument +in: zone specifies the timezone for the returned time:

Time.at(secs, in: '+12:00') # => 2001-01-01 17:59:59 +1200
Time.at(secs, in: '-12:00') # => 2000-12-31 17:59:59 -1200

For the forms of argument zone, see Timezone Specifiers.

Reads and returns a line without echo back. Prints prompt unless it is nil.

The newline character that terminates the read line is removed from the returned string, see String#chomp!.

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

Returns status information for ios as an object of type File::Stat.

f = File.new("testfile")
s = f.stat
"%o" % s.mode   #=> "100644"
s.blksize       #=> 4096
s.atime         #=> Wed Apr 09 08:53:54 CDT 2003

Get the internal timeout duration or nil if it was not set.

Set the internal timeout to the specified duration or nil. The timeout applies to all blocking operations where possible.

This affects the following methods (but is not limited to): gets, puts, read, write, wait_readable and wait_writable. This also affects blocking socket operations like Socket#accept and Socket#connect.

Some operations like File#open and IO#close are not affected by the timeout. A timeout during a write operation may leave the IO in an inconsistent state, e.g. data was partially written. Generally speaking, a timeout is a last ditch effort to prevent an application from hanging on slow I/O operations, such as those that occur during a slowloris attack.

Immediately writes to disk all data buffered in the stream, via the operating system’s: fdatasync(2), if supported, otherwise via fsync(2), if supported; otherwise raises an exception.

Reads up to maxlen bytes from the stream; returns a string (either a new string or the given out_string). Its encoding is:

With the single non-negative integer argument maxlen given, returns a new string:

f = File.new('t.txt')
f.readpartial(20) # => "First line\nSecond l"
f.readpartial(20) # => "ine\n\nFourth line\n"
f.readpartial(20) # => "Fifth line\n"
f.readpartial(20) # Raises EOFError.
f.close

With both argument maxlen and string argument out_string given, returns modified out_string:

f = File.new('t.txt')
s = 'foo'
f.readpartial(20, s) # => "First line\nSecond l"
s = 'bar'
f.readpartial(0, s)  # => ""
f.close

This method is useful for a stream such as a pipe, a socket, or a tty. It blocks only when no data is immediately available. This means that it blocks only when all of the following are true:

When blocked, the method waits for either more data or EOF on the stream:

When not blocked, the method responds immediately:

Note that this method is similar to sysread. The differences are:

The latter means that readpartial is non-blocking-flag insensitive. It blocks on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking mode.

Examples:

#                        # Returned      Buffer Content    Pipe Content
r, w = IO.pipe           #
w << 'abc'               #               ""                "abc".
r.readpartial(4096)      # => "abc"      ""                ""
r.readpartial(4096)      # (Blocks because buffer and pipe are empty.)

#                        # Returned      Buffer Content    Pipe Content
r, w = IO.pipe           #
w << 'abc'               #               ""                "abc"
w.close                  #               ""                "abc" EOF
r.readpartial(4096)      # => "abc"      ""                 EOF
r.readpartial(4096)      # raises EOFError

#                        # Returned      Buffer Content    Pipe Content
r, w = IO.pipe           #
w << "abc\ndef\n"        #               ""                "abc\ndef\n"
r.gets                   # => "abc\n"    "def\n"           ""
w << "ghi\n"             #               "def\n"           "ghi\n"
r.readpartial(4096)      # => "def\n"    ""                "ghi\n"
r.readpartial(4096)      # => "ghi\n"    ""                ""

Returns true if the stream is associated with a terminal device (tty), false otherwise:

f = File.new('t.txt').isatty    #=> false
f.close
f = File.new('/dev/tty').isatty #=> true
f.close

IO#tty? is an alias for IO#isatty.

Returns true if object is an element of self, false otherwise:

(1..4).include?(2)        # => true
(1..4).include?(5)        # => false
(1..4).include?(4)        # => true
(1...4).include?(4)       # => false
('a'..'d').include?('b')  # => true
('a'..'d').include?('e')  # => false
('a'..'d').include?('B')  # => false
('a'..'d').include?('d')  # => true
('a'...'d').include?('d') # => false

If begin and end are numeric, include? behaves like cover?

(1..3).include?(1.5) # => true
(1..3).cover?(1.5) # => true

But when not numeric, the two methods may differ:

('a'..'d').include?('cc') # => false
('a'..'d').cover?('cc')   # => true

Related: Range#cover?.

Range#member? is an alias for Range#include?.

With no block given, returns the MatchData object that describes the match, if any, or nil if none; the search begins at the given character offset in string:

/abra/.match('abracadabra')      # => #<MatchData "abra">
/abra/.match('abracadabra', 4)   # => #<MatchData "abra">
/abra/.match('abracadabra', 8)   # => nil
/abra/.match('abracadabra', 800) # => nil

string = "\u{5d0 5d1 5e8 5d0}cadabra"
/abra/.match(string, 7)          #=> #<MatchData "abra">
/abra/.match(string, 8)          #=> nil
/abra/.match(string.b, 8)        #=> #<MatchData "abra">

With a block given, calls the block if and only if a match is found; returns the block’s value:

/abra/.match('abracadabra') {|matchdata| p matchdata }
# => #<MatchData "abra">
/abra/.match('abracadabra', 4) {|matchdata| p matchdata }
# => #<MatchData "abra">
/abra/.match('abracadabra', 8) {|matchdata| p matchdata }
# => nil
/abra/.match('abracadabra', 8) {|marchdata| fail 'Cannot happen' }
# => nil

Output (from the first two blocks above):

#<MatchData "abra">
#<MatchData "abra">

 /(.)(.)(.)/.match("abc")[2] # => "b"
 /(.)(.)/.match("abc", 1)[2] # => "c"

Returns true or false to indicate whether the regexp is matched or not without updating $~ and other related variables. If the second parameter is present, it specifies the position in the string to begin the search.

/R.../.match?("Ruby")    # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby")    # => false
$&                       # => nil

It returns the timeout interval for Regexp matching in second. nil means no default timeout configuration.

This configuration is per-object. The global configuration set by Regexp.timeout= is ignored if per-object configuration is set.

re = Regexp.new("^a*b?a*$", timeout: 1)
re.timeout               #=> 1.0
re =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)

It returns the current default timeout interval for Regexp matching in second. nil means no default timeout configuration.

It sets the default timeout interval for Regexp matching in second. nil means no default timeout configuration. This configuration is process-global. If you want to set timeout for each Regexp, use timeout keyword for Regexp.new.

Regexp.timeout = 1
/^a*b?a*$/ =~ "a" * 100000 + "x" #=> regexp match timeout (RuntimeError)
No documentation available

Returns a new set that is a copy of the set, flattening each containing set recursively.

Equivalent to Set#flatten, but replaces the receiver with the result in place. Returns nil if no modifications were made.

No documentation available

Merges the elements of the given enumerable object to the set and returns self.

Returns the member names of the Struct descendant as an array:

Customer = Struct.new(:name, :address, :zip)
Customer.members # => [:name, :address, :zip]

Returns the number of members.

Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
joe.size #=> 3

Struct#length is an alias for Struct#size.

Returns the member names from self as an array:

Customer = Struct.new(:name, :address, :zip)
Customer.new.members # => [:name, :address, :zip]

Related: to_a.

Equivalent to self.to_s.length; see String#length.

Symbol#size is an alias for Symbol#length.

Equivalent to self.to_s.match, including possible updates to global variables; see String#match.

Search took: 5ms  ·  Total Results: 2267