Parse a file at filename
. Returns the Psych::Nodes::Document
.
Raises a Psych::SyntaxError
when a YAML
syntax error is detected.
Safely dump Ruby object o
to a YAML
string. Optional options
may be passed in to control the output format. If an IO
object is passed in, the YAML
will be dumped to that IO
object. By default, only the following classes are allowed to be serialized:
Arbitrary classes can be allowed by adding those classes to the permitted_classes
keyword argument. They are additive. For example, to allow Date
serialization:
Psych.safe_dump(yaml, permitted_classes: [Date])
Now the Date
class can be dumped in addition to the classes listed above.
A Psych::DisallowedClass
exception will be raised if the object contains a class that isn’t in the permitted_classes
list.
Currently supported options are:
:indentation
Number of space characters used to indent. Acceptable value should be in 0..9
range, otherwise option is ignored.
Default: 2
.
:line_width
Max character to wrap line at.
Default: 0
(meaning “wrap at 81”).
:canonical
Write “canonical” YAML
form (very verbose, yet strictly formal).
Default: false
.
:header
Write %YAML [version]
at the beginning of document.
Default: false
.
Example:
# Dump an array, get back a YAML string Psych.safe_dump(['a', 'b']) # => "---\n- a\n- b\n" # Dump an array to an IO object Psych.safe_dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890> # Dump an array with indentation set Psych.safe_dump(['a', ['b']], indentation: 3) # => "---\n- a\n- - b\n" # Dump an array to an IO with indentation set Psych.safe_dump(['a', ['b']], StringIO.new, indentation: 3)
Dump a list of objects as separate documents to a document stream.
Example:
Psych.dump_stream("foo\n ", {}) # => "--- ! \"foo\\n \"\n--- {}\n"
Loads the document contained in filename
. Returns the yaml contained in filename
as a Ruby object, or if the file is empty, it returns the specified fallback
return value, which defaults to false
. See load for options.
Delete text between start and end in the current line.
See GNU Readline’s rl_delete_text function.
Raises NotImplementedError
if the using readline library does not support.
Combine two Adler-32 check values in to one. alder1
is the first Adler-32 value, adler2
is the second Adler-32 value. len2
is the length of the string used to generate adler2
.
Returns the table for calculating CRC checksum as an array.
Returns true
if the named file is readable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.
If file_name is readable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_readable?("/etc/passwd") #=> 420 m = File.world_readable?("/etc/passwd") sprintf("%o", m) #=> "644"
Returns true
if the named file is writable by the real user and group id of this process. See access(3).
Note that some OS-level security features may cause this to return true even though the file is not writable by the real user/group.
If file_name is writable by others, returns an integer representing the file permission bits of file_name. Returns nil
otherwise. The meaning of the bits is platform dependent; on Unix systems, see stat(2)
.
file_name can be an IO
object.
File.world_writable?("/tmp") #=> 511 m = File.world_writable?("/tmp") sprintf("%o", m) #=> "777"
Returns true
if the named file is executable by the real user and group id of this process. See access(3).
Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.
Note that some OS-level security features may cause this to return true even though the file is not executable by the real user/group.
Returns the Base64-decoded version of str
. This method complies with “Base 64 Encoding
with URL and Filename Safe Alphabet” in RFC 4648. The alphabet uses ‘-’ instead of ‘+’ and ‘_’ instead of ‘/’.
The padding character is optional. This method accepts both correctly-padded and unpadded input. Note that it still rejects incorrectly-padded input.
Removes server
from the list of registered servers.
Removes server
from the list of registered servers.
Copies file contents of src
to dest
. Both of src
and dest
must be a path name.
Copies file contents of src
to dest
. Both of src
and dest
must be a path name.
This method removes a file system entry path
. path
might be a regular file, a directory, or something. If path
is a directory, remove it recursively.
See also remove_entry_secure.
This method removes a file system entry path
. path
might be a regular file, a directory, or something. If path
is a directory, remove it recursively.
See also remove_entry_secure.
Removes a directory dir
and its contents recursively. This method ignores StandardError
if force
is true.
Removes a directory dir
and its contents recursively. This method ignores StandardError
if force
is true.
Returns true if the contents of a file a
and a file b
are identical.
FileUtils.compare_file('somefile', 'somefile') #=> true FileUtils.compare_file('/dev/null', '/dev/urandom') #=> false
Returns true if the contents of a file a
and a file b
are identical.
FileUtils.compare_file('somefile', 'somefile') #=> true FileUtils.compare_file('/dev/null', '/dev/urandom') #=> false