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::BadAlias
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 full line that is being edited. This is useful from within the complete_proc for determining the context of the completion request.
The length of Readline.line_buffer
and GNU Readline’s rl_end are same.
Raises NotImplementedError
if the using readline library does not support.
Insert text into the line at the current cursor position.
See GNU Readline’s rl_insert_text function.
Raises NotImplementedError
if the using readline library does not support.
Returns the string which represents the version of zlib library.
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 a sharable hash map of error types and spell checker objects.
Adds DidYouMean
functionality to an error using a given spell checker
Start a dRuby server locally.
The new dRuby server will become the primary server, even if another server is currently the primary server.
uri
is the URI
for the server to bind to. If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.
front
is the server’s front object. This may be nil.
config
is the configuration for the new server. This may be nil.
See DRbServer::new
.
Start a dRuby server locally.
The new dRuby server will become the primary server, even if another server is currently the primary server.
uri
is the URI
for the server to bind to. If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.
front
is the server’s front object. This may be nil.
config
is the configuration for the new server. This may be nil.
See DRbServer::new
.
Stop the local dRuby server.
This operates on the primary server. If there is no primary server currently running, it is a noop.
Stop the local dRuby server.
This operates on the primary server. If there is no primary server currently running, it is a noop.
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.