Removes trailing whitespace from the receiver. Returns the altered receiver, or nil
if no change was made. See also String#lstrip!
and String#strip!
.
Refer to String#strip
for the definition of whitespace.
" hello ".rstrip! #=> " hello" " hello".rstrip! #=> nil "hello".rstrip! #=> nil
Returns the current fiber. You need to require 'fiber'
before using this method. If you are not running in the context of a fiber this method will return the root fiber.
Returns an array containing all of the filenames in the given directory. Will raise a SystemCallError
if the named directory doesn’t exist.
The optional encoding keyword argument specifies the encoding of the directory. If not specified, the filesystem encoding is used.
Dir.entries("testdir") #=> [".", "..", "config.h", "main.rb"]
Returns true
if the named file is writable by the effective user and group id of this process. See eaccess(3).
With no arguments, sets the default visibility for subsequently defined methods to private. With arguments, sets the named methods to have private visibility. String
arguments are converted to symbols.
module Mod def a() end def b() end private def c() end private :a end Mod.private_instance_methods #=> [:a, :c]
Note that to show a private method on RDoc
, use :doc:
.
Returns true if the date is Thursday.
Returns true if the date is Friday.
Returns true if the date is Saturday.
Returns true if the date is on or after the day of calendar reform.
Date.new(1582,10,15).gregorian? #=> true (Date.new(1582,10,15) - 1).gregorian? #=> false
This method is equivalent to new_start
(Date::GREGORIAN
).
Returns the hour of the day (0..23) for time.
t = Time.now #=> 2007-11-19 08:26:20 -0600 t.hour #=> 8
Returns true
if time represents Thursday.
t = Time.local(1995, 12, 21) #=> 1995-12-21 00:00:00 -0600 t.thursday? #=> true
Returns true
if time represents Friday.
t = Time.local(1987, 12, 18) #=> 1987-12-18 00:00:00 -0600 t.friday? #=> true
Returns true
if time represents Saturday.
t = Time.local(2006, 6, 10) #=> 2006-06-10 00:00:00 -0500 t.saturday? #=> true
Opens the file, optionally seeks to the given offset, writes string, then returns the length written. write
ensures the file is closed before returning. If offset is not given in write mode, the file is truncated. Otherwise, it is not truncated.
IO.write("testfile", "0123456789", 20) #=> 10 # File could contain: "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n" IO.write("testfile", "0123456789") #=> 10 # File would now read: "0123456789"
If the last argument is a hash, it specifies options for the internal open(). It accepts the following keys:
string or encoding
Specifies the encoding of the read string. See Encoding.aliases
for possible encodings.
string or integer
Specifies the mode argument for open(). It must start with “w”, “a”, or “r+”, otherwise it will cause an error. See IO.new
for the list of possible modes.
integer
Specifies the perm argument for open().
array
Specifies arguments for open() as an array. This key can not be used in combination with other keys.
Same as IO.write
except opening the file in binary mode and ASCII-8BIT encoding (“wb:ASCII-8BIT”).
Writes the given object(s) to ios. Returns nil
.
The stream must be opened for writing. Each given object that isn’t a string will be converted by calling its to_s
method. When called without arguments, prints the contents of $_
.
If the output field separator ($,
) is not nil
, it is inserted between objects. If the output record separator ($\
) is not nil
, it is appended to the output.
$stdout.print("This is ", 100, " percent.\n")
produces:
This is 100 percent.
Formats and writes to ios, converting parameters under control of the format string. See Kernel#sprintf
for details.
Writes the given string to ios using a low-level write. Returns the number of bytes written. Do not mix with other methods that write to ios or you may get unpredictable results. Raises SystemCallError
on error.
f = File.new("out", "w") f.syswrite("ABCDEF") #=> 6
Writes the given string to ios at offset using pwrite() system call. This is advantageous to combining IO#seek
and IO#write
in that it is atomic, allowing multiple threads/process to share the same IO
object for reading the file at various locations. This bypasses any userspace buffering of the IO
layer. Returns the number of bytes written. Raises SystemCallError
on error and NotImplementedError
if platform does not implement the system call.
File.open("out", "w") do |f| f.pwrite("ABCDEF", 3) #=> 6 end File.read("out") #=> "\u0000\u0000\u0000ABCDEF"
Writes the given strings to ios. The stream must be opened for writing. Arguments that are not a string will be converted to a string using to_s
. Returns the number of bytes written in total.
count = $stdout.write("This is", " a test\n") puts "That was #{count} bytes of data"
produces:
This is a test That was 15 bytes of data