Returns a copy of self with leading whitespace removed; see Whitespace in Strings:
whitespace = "\x00\t\n\v\f\r " s = whitespace + 'abc' + whitespace s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r " s.lstrip # => "abc\u0000\t\n\v\f\r "
Related: String#rstrip, String#strip.
Returns a copy of the receiver with trailing whitespace removed; see Whitespace in Strings:
whitespace = "\x00\t\n\v\f\r " s = whitespace + 'abc' + whitespace s # => "\u0000\t\n\v\f\r abc\u0000\t\n\v\f\r " s.rstrip # => "\u0000\t\n\v\f\r abc"
Related: String#lstrip, String#strip.
Like String#strip, except that any modifications are made in self; returns self if any modification are made, nil otherwise.
Related: String#lstrip!, String#strip!.
Like String#lstrip, except that any modifications are made in self; returns self if any modification are made, nil otherwise.
Related: String#rstrip!, String#strip!.
Like String#rstrip, except that any modifications are made in self; returns self if any modification are made, nil otherwise.
Related: String#lstrip!, String#strip!.
Returns the current fiber. 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).
Note that some OS-level security features may cause this to return true even though the file is not writable by the effective user/group.
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. An Array of Symbols and/or Strings is also accepted. If a single argument is passed, it is returned. If no argument is passed, nil is returned. If multiple arguments are passed, the arguments are returned as an array.
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:.
Print an argument or list of arguments to the default output stream
cgi = CGI.new cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
Returns true if self is a Thursday, false otherwise.
Returns true if self is a Friday, false otherwise.
Returns true if self is a Saturday, false otherwise.
Returns true if the date is on or after the date of calendar reform, false otherwise:
Date.new(1582, 10, 15).gregorian? # => true (Date.new(1582, 10, 15) - 1).gregorian? # => false
Equivalent to Date#new_start with argument Date::GREGORIAN.
Returns the integer hour of the day for self, in range (0..23):
t = Time.new(2000, 1, 2, 3, 4, 5, 6) # => 2000-01-02 03:04:05 +000006 t.hour # => 3
Returns true if self represents a Thursday, false otherwise:
t = Time.utc(2000, 1, 6) # => 2000-01-06 00:00:00 UTC t.thursday? # => true
Related: Time#friday?, Time#saturday?, Time#sunday?.
Returns true if self represents a Friday, false otherwise:
t = Time.utc(2000, 1, 7) # => 2000-01-07 00:00:00 UTC t.friday? # => true
Related: Time#saturday?, Time#sunday?, Time#monday?.
Returns true if self represents a Saturday, false otherwise:
t = Time.utc(2000, 1, 1) # => 2000-01-01 00:00:00 UTC t.saturday? # => true
Related: Time#sunday?, Time#monday?, Time#tuesday?.
Opens the stream, writes the given data to it, and closes the stream; returns the number of bytes written.
When called from class IO (but not subclasses of IO), this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
The first argument must be a string; its meaning depends on whether it starts with the pipe character ('|'):
If so (and if self is IO), the rest of the string is a command to be executed as a subprocess.
Otherwise, the string is the path to a file.
With argument command given, executes the command in a shell, passes data through standard input, writes its output to $stdout, and returns the length of the given data:
IO.write('| cat', 'Hello World!') # => 12
Output:
Hello World!
With argument path given, writes the given data to the file at that path:
IO.write('t.tmp', 'abc') # => 3 File.read('t.tmp') # => "abc"
If offset is zero (the default), the file is overwritten:
IO.write('t.tmp', 'A') # => 1 File.read('t.tmp') # => "A"
If offset in within the file content, the file is partly overwritten:
IO.write('t.tmp', 'abcdef') # => 3 File.read('t.tmp') # => "abcdef" # Offset within content. IO.write('t.tmp', '012', 2) # => 3 File.read('t.tmp') # => "ab012f"
If offset is outside the file content, the file is padded with null characters "\u0000":
IO.write('t.tmp', 'xyz', 10) # => 3 File.read('t.tmp') # => "ab012f\u0000\u0000\u0000\u0000xyz"
Optional keyword arguments opts specify:
Encoding options.
Behaves like IO.write, except that the stream is opened in binary mode with ASCII-8BIT encoding.
When called from class IO (but not subclasses of IO), this method has potential security vulnerabilities if called with untrusted input; see Command Injection.
Writes the given objects to the stream; returns nil. Appends the output record separator $OUTPUT_RECORD_SEPARATOR ($\), if it is not nil. See Line IO.
With argument objects given, for each object:
Converts via its method to_s if not a string.
Writes to the stream.
If not the last object, writes the output field separator $OUTPUT_FIELD_SEPARATOR ($,) if it is not nil.
With default separators:
f = File.open('t.tmp', 'w+') objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero'] p $OUTPUT_RECORD_SEPARATOR p $OUTPUT_FIELD_SEPARATOR f.print(*objects) f.rewind p f.read f.close
Output:
nil nil "00.00/10+0izerozero"
With specified separators:
$\ = "\n" $, = ',' f.rewind f.print(*objects) f.rewind p f.read
Output:
"0,0.0,0/1,0+0i,zero,zero\n"
With no argument given, writes the content of $_ (which is usually the most recent user input):
f = File.open('t.tmp', 'w+') gets # Sets $_ to the most recent user input. f.print f.close