Results for: "module_function"

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.

:stringify_names

Dump symbol keys in Hash objects as string.

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 hash with symbol keys as string
Psych.dump({a: "b"}, stringify_names: true) # => "---\na: b\n"

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.

Combine two Adler-32 check values in to one. adler1 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.

Reset the dir and path values. The next time dir or path is requested, the values will be calculated from scratch. This is mainly used by the unit tests to provide test isolation.

Returns a list of paths matching glob that can be used by a gem to pick up features from other gems. For example:

Gem.find_files('rdoc/discover').each do |path| load path end

if check_load_path is true (the default), then find_files also searches $LOAD_PATH for files as well as gems.

Note that find_files will return all files even if they are from different versions of the same gem. See also find_latest_files

Open a file with given flags, and on Windows protect access with flock

An Array of the default sources that come with RubyGems

Default home directory path to be used if an alternate value is not specified in the environment

The path to standard location of the user’s state file.

Default gem load path

The default directory for binaries

Default options for gem commands for Ruby implementers.

The options here should be structured as an array of string “gem” command names as keys and a string of the default options as values.

Example:

def self.platform_defaults

{
    'install' => '--no-rdoc --no-ri --env-shebang',
    'update' => '--no-rdoc --no-ri --env-shebang'
}

end

Copies file from src to dest, which should not be directories.

Arguments src and dest should be interpretable as paths.

Examples:

FileUtils.touch('src0.txt')
FileUtils.copy_file('src0.txt', 'dest0.txt')
File.file?('dest0.txt') # => true

Keyword arguments:

Related: methods for copying.

Copies file from src to dest, which should not be directories.

Arguments src and dest should be interpretable as paths.

Examples:

FileUtils.touch('src0.txt')
FileUtils.copy_file('src0.txt', 'dest0.txt')
File.file?('dest0.txt') # => true

Keyword arguments:

Related: methods for copying.

Removes the entry given by path, which should be the entry for a regular file, a symbolic link, or a directory.

Argument path should be interpretable as a path.

Optional argument force specifies whether to ignore raised exceptions of StandardError and its descendants.

Related: FileUtils.remove_entry_secure.

Removes the entry given by path, which should be the entry for a regular file, a symbolic link, or a directory.

Argument path should be interpretable as a path.

Optional argument force specifies whether to ignore raised exceptions of StandardError and its descendants.

Related: FileUtils.remove_entry_secure.

Recursively removes the directory entry given by path, which should be the entry for a regular file, a symbolic link, or a directory.

Argument path should be interpretable as a path.

Optional argument force specifies whether to ignore raised exceptions of StandardError and its descendants.

Related: methods for deleting.

Recursively removes the directory entry given by path, which should be the entry for a regular file, a symbolic link, or a directory.

Argument path should be interpretable as a path.

Optional argument force specifies whether to ignore raised exceptions of StandardError and its descendants.

Related: methods for deleting.

Search took: 8ms  ·  Total Results: 5313