Returns a new Time
object representing time in UTC.
t = Time.local(2000,1,1,20,15,1) #=> 2000-01-01 20:15:01 -0600 t.gmt? #=> false y = t.getgm #=> 2000-01-02 02:15:01 UTC y.gmt? #=> true t == y #=> true
Closes the database.
Returns true if the database is closed, false otherwise.
Returns a Hash
(not a DBM
database) created by using each value in the database as a key, with the corresponding key as its value.
Returns true if the database contains the specified key, false otherwise.
Returns the struct members as an array of symbols:
Customer = Struct.new(:name, :address, :zip) joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345) joe.members #=> [:name, :address, :zip]
Reads and returns a character in raw mode.
You must require ‘io/console’ to use this method.
Reads and returns a line without echo back. Prints prompt
unless it is nil
.
You must require ‘io/console’ to use this method.
Returns true
if an IO
object is in non-blocking mode.
Enables non-blocking mode on a stream when set to true
, and blocking mode when set to false
.
Yields self
in non-blocking mode.
When false
is given as an argument, self
is yielded in blocking mode. The original mode is restored after the block is executed.
Reads the next “line” from the I/O stream; lines are separated by sep. A separator of nil
reads the entire contents, and a zero-length separator reads the input a paragraph at a time (two successive newlines in the input separate paragraphs). The stream must be opened for reading or an IOError
will be raised. The line read in will be returned and also assigned to $_
. Returns nil
if called at end of file. If the first argument is an integer, or optional second argument is given, the returning string would not be longer than the given value in bytes.
File.new("testfile").gets #=> "This is line one\n" $_ #=> "This is line one\n" File.new("testfile").gets(4)#=> "This"
If IO
contains multibyte characters byte then gets(1)
returns character entirely:
# Russian characters take 2 bytes File.write("testfile", "\u{442 435 441 442}") File.open("testfile") {|f|f.gets(1)} #=> "\u0442" File.open("testfile") {|f|f.gets(2)} #=> "\u0442" File.open("testfile") {|f|f.gets(3)} #=> "\u0442\u0435" File.open("testfile") {|f|f.gets(4)} #=> "\u0442\u0435"
Reads a one-character string from ios. Returns nil
if called at end of file.
f = File.new("testfile") f.getc #=> "h" f.getc #=> "e"
Gets the next 8-bit byte (0..255) from ios. Returns nil
if called at end of file.
f = File.new("testfile") f.getbyte #=> 84 f.getbyte #=> 104
Pushes back bytes (passed as a parameter) onto ios, such that a subsequent buffered read will return it. Only one byte may be pushed back before a subsequent read operation (that is, you will be able to read only the last of several bytes that have been pushed back). Has no effect with unbuffered reads (such as IO#sysread
).
f = File.new("testfile") #=> #<File:testfile> b = f.getbyte #=> 0x38 f.ungetbyte(b) #=> nil f.getbyte #=> 0x38
Pushes back one character (passed as a parameter) onto ios, such that a subsequent buffered character read will return it. Only one character may be pushed back before a subsequent read operation (that is, you will be able to read only the last of several characters that have been pushed back). Has no effect with unbuffered reads (such as IO#sysread
).
f = File.new("testfile") #=> #<File:testfile> c = f.getc #=> "8" f.ungetc(c) #=> nil f.getc #=> "8"
Closes ios and flushes any pending writes to the operating system. The stream is unavailable for any further data operations; an IOError
is raised if such an attempt is made. I/O streams are automatically closed when they are claimed by the garbage collector.
If ios is opened by IO.popen
, close
sets $?
.
Calling this method on closed IO
object is just ignored since Ruby 2.3.
Returns true
if ios is completely closed (for duplex streams, both reader and writer), false
otherwise.
f = File.new("testfile") f.close #=> nil f.closed? #=> true f = IO.popen("/bin/sh","r+") f.close_write #=> nil f.closed? #=> false f.close_read #=> nil f.closed? #=> true
Returns true
if the underlying file descriptor of ios will be closed automatically at its finalization, otherwise false
.
Sets auto-close flag.
f = open("/dev/null") IO.for_fd(f.fileno) # ... f.gets # may cause IOError f = open("/dev/null") IO.for_fd(f.fileno).autoclose = true # ... f.gets # won't cause IOError
Closes the associated database file.
Returns true if the associated database file has been closed.
Returns a hash created by using gdbm’s values as keys, and the keys as values.
Returns true if the given key k exists within the database. Returns false otherwise.
Returns true
if obj
is an element of the range, false
otherwise. If begin and end are numeric, comparison is done according to the magnitude of the values.
("a".."z").include?("g") #=> true ("a".."z").include?("A") #=> false ("a".."z").include?("cc") #=> false