Load yaml
in to a Ruby data structure. If multiple documents are provided, the object contained in the first document will be returned. filename
will be used in the exception message if any exception is raised while parsing. If yaml
is empty, it returns the specified fallback
return value, which defaults to false
.
Raises a Psych::SyntaxError
when a YAML
syntax error is detected.
Example:
Psych.unsafe_load("--- a") # => 'a' Psych.unsafe_load("---\n - a\n - b") # => ['a', 'b'] begin Psych.unsafe_load("--- `", filename: "file.txt") rescue Psych::SyntaxError => ex ex.file # => 'file.txt' ex.message # => "(file.txt): found character that cannot start any token" end
When the optional symbolize_names
keyword argument is set to a true value, returns symbols for keys in Hash
objects (default: strings).
Psych.unsafe_load("---\n foo: bar") # => {"foo"=>"bar"} Psych.unsafe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
Raises a TypeError
when ‘yaml` parameter is NilClass
NOTE: This method *should not* be used to parse untrusted documents, such as YAML
documents that are supplied via user input. Instead, please use the load method or the safe_load
method.
Safely load the yaml string in yaml
. By default, only the following classes are allowed to be deserialized:
Recursive data structures are not allowed by default. Arbitrary classes can be allowed by adding those classes to the permitted_classes
keyword argument. They are additive. For example, to allow Date
deserialization:
Psych.safe_load(yaml, permitted_classes: [Date])
Now the Date
class can be loaded in addition to the classes listed above.
Aliases can be explicitly allowed by changing the aliases
keyword argument. For example:
x = [] x << x yaml = Psych.dump x Psych.safe_load yaml # => raises an exception Psych.safe_load yaml, aliases: true # => loads the aliases
A Psych::DisallowedClass
exception will be raised if the yaml contains a class that isn’t in the permitted_classes
list.
A Psych::AliasesNotEnabled
exception will be raised if the yaml contains aliases but the aliases
keyword argument is set to false.
filename
will be used in the exception message if any exception is raised while parsing.
When the optional symbolize_names
keyword argument is set to a true value, returns symbols for keys in Hash
objects (default: strings).
Psych.safe_load("---\n foo: bar") # => {"foo"=>"bar"} Psych.safe_load("---\n foo: bar", symbolize_names: true) # => {:foo=>"bar"}
Load multiple documents given in yaml
. Returns the parsed documents as a list. If a block is given, each document will be converted to Ruby and passed to the block during parsing
Example:
Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar'] list = [] Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby| list << ruby end list # => ['foo', 'bar']
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.
Returns the version of libyaml being used
Returns the string which represents the version of zlib library.
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
.
Alias of GC.start
The version of the Marshal
format for your Ruby.
A Gem::Version
for the currently running Ruby.
Glob pattern for require-able path suffixes.
Regexp
for require-able path suffixes.
Find
rubygems plugin files in the standard location and load them
Looks for a gem dependency file at path
and activates the gems in the file if found. If the file is not found an ArgumentError
is raised.
If path
is not given the RUBYGEMS_GEMDEPS environment variable is used, but if no file is found no exception is raised.
If ‘-’ is given for path
RubyGems searches up from the current working directory for gem dependency files (gem.deps.rb, Gemfile, Isolate) and activates the gems in the first one found.
You can run this automatically when rubygems starts. To enable, set the RUBYGEMS_GEMDEPS
environment variable to either the path of your gem dependencies file or “-” to auto-discover in parent directories.
NOTE: Enabling automatic discovery on multiuser systems can lead to execution of arbitrary code when used from directories outside your control.
The home directory for the user.
Path for gems in the user’s home directory
Returns a sharable hash map of error types and spell checker objects.
Adds DidYouMean
functionality to an error using a given spell checker
Returns whether or not the given header
file can be found on your system. If found, a macro is passed as a preprocessor constant to the compiler using the header file name, in uppercase, prepended with HAVE_
.
For example, if have_header('foo.h')
returned true, then the HAVE_FOO_H
preprocessor macro would be passed to the compiler.
Instructs mkmf to search for the given header
in any of the paths
provided, and returns whether or not it was found in those paths.
If the header is found then the path it was found on is added to the list of included directories that are sent to the compiler (via the -I
switch).
Returns the convertible integer type of the given type
. You may optionally specify additional headers
to search in for the type
. convertible means actually the same type, or typedef’d from the same type.
If the type
is an integer type and the convertible type is found, the following macros are passed as preprocessor constants to the compiler using the type
name, in uppercase.
TYPEOF_
, followed by the type
name, followed by =X
where “X” is the found convertible type name.
TYP2NUM
and NUM2TYP
, where TYP
is the type
name in uppercase with replacing an _t
suffix with “T”, followed by =X
where “X” is the macro name to convert type
to an Integer
object, and vice versa.
For example, if foobar_t
is defined as unsigned long, then convertible_int("foobar_t")
would return “unsigned long”, and define these macros:
#define TYPEOF_FOOBAR_T unsigned long #define FOOBART2NUM ULONG2NUM #define NUM2FOOBART NUM2ULONG
Generates a header file consisting of the various macro definitions generated by other methods such as have_func
and have_header. These are then wrapped in a custom #ifndef
based on the header
file name, which defaults to “extconf.h”.
For example:
# extconf.rb require 'mkmf' have_func('realpath') have_header('sys/utime.h') create_header create_makefile('foo')
The above script would generate the following extconf.h file:
#ifndef EXTCONF_H #define EXTCONF_H #define HAVE_REALPATH 1 #define HAVE_SYS_UTIME_H 1 #endif
Given that the create_header
method generates a file based on definitions set earlier in your extconf.rb file, you will probably want to make this one of the last methods you call in your script.
Registers the given klass
as the class to be instantiated when parsing a URI with the given scheme
:
URI.register_scheme('MS_SEARCH', URI::Generic) # => URI::Generic URI.scheme_list['MS_SEARCH'] # => URI::Generic
Note that after calling String#upcase
on scheme
, it must be a valid constant name.