{: rooto:"YARD::CodeObjects::RootObject:@childrenIC:&YARD::CodeObjects::CodeObjectList[o:$YARD::CodeObjects::ModuleObject;IC;[Jo:#YARD::CodeObjects::ClassObject;IC;[o:$YARD::CodeObjects::MethodObject:@module_functionF:@scope:
instance:@visibility:public:
@pathI"Zlib::ZStream#avail_out:EF:@parameters[ :@files[[I"ext/zlib/zlib.c;Ti:@current_file_has_commentsT:
@name:avail_out:@source_type0:
@tags[ :@docstrings{ :@docstringIC:YARD::Docstring"Returns number of bytes of free spaces in output buffer. Because the free
space is allocated automatically, this method returns 0 normally.
;T;[ :@ref_tags[ : @allI"Returns number of bytes of free spaces in output buffer. Because the free
space is allocated automatically, this method returns 0 normally.
;T:@unresolved_reference0:@object@:@hash_flagF:@line_rangeo:
Range: exclT:
begini:endi:@namespace@
:@sourceI"static VALUE
rb_zstream_avail_out(VALUE obj)
{
struct zstream *z;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
return rb_uint2inum(z->stream.avail_out);
};T:@signatureI"static VALUE;T:@explicitTo;;F;
;;;;I"Zlib::ZStream#avail_out=;F;[[I" size;T0;[[@i;T;:avail_out=;0;[ ;{ ;IC;"Allocates +size+ bytes of free space in the output buffer. If there are more
than +size+ bytes already in the buffer, the buffer is truncated. Because
free space is allocated automatically, you usually don't need to use this
method.
;T;[ ;[ ;I"Allocates +size+ bytes of free space in the output buffer. If there are more
than +size+ bytes already in the buffer, the buffer is truncated. Because
free space is allocated automatically, you usually don't need to use this
method.
;T;0; @;!F;"o;#;$T;%i;&i;'@
;(I"static VALUE
rb_zstream_set_avail_out(VALUE obj, VALUE size)
{
struct zstream *z = get_zstream(obj);
zstream_expand_buffer_into(z, FIX2INT(size));
return size;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#avail_in;F;[ ;[[@i;T;:
avail_in;0;[ ;{ ;IC;"DReturns bytes of data in the input buffer. Normally, returns 0.
;T;[ ;[ ;I"EReturns bytes of data in the input buffer. Normally, returns 0.
;T;0; @+;!F;"o;#;$T;%i;&i;'@
;(I"static VALUE
rb_zstream_avail_in(VALUE obj)
{
struct zstream *z;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#total_in;F;[ ;[[@i;T;:
total_in;0;[ ;{ ;IC;"DReturns the total bytes of the input data to the stream. FIXME
;T;[ ;[ ;I"EReturns the total bytes of the input data to the stream. FIXME
;T;0; @9;!F;"o;#;$T;%i;&i;'@
;(I"pstatic VALUE
rb_zstream_total_in(VALUE obj)
{
return rb_uint2inum(get_zstream(obj)->stream.total_in);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#total_out;F;[ ;[[@i;T;:total_out;0;[ ;{ ;IC;"GReturns the total bytes of the output data from the stream. FIXME
;T;[ ;[ ;I"HReturns the total bytes of the output data from the stream. FIXME
;T;0; @G;!F;"o;#;$T;%i;&i;'@
;(I"rstatic VALUE
rb_zstream_total_out(VALUE obj)
{
return rb_uint2inum(get_zstream(obj)->stream.total_out);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#data_type;F;[ ;[[@i;T;:data_type;0;[ ;{ ;IC;"Guesses the type of the data which have been inputed into the stream. The
returned value is either BINARY, ASCII, or
UNKNOWN.
;T;[ ;[ ;I"Guesses the type of the data which have been inputed into the stream. The
returned value is either BINARY, ASCII, or
UNKNOWN.
;T;0; @U;!F;"o;#;$T;%i;&i;'@
;(I"mstatic VALUE
rb_zstream_data_type(VALUE obj)
{
return INT2FIX(get_zstream(obj)->stream.data_type);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#adler;F;[ ;[[@i;T;:
adler;0;[ ;{ ;IC;"#Returns the adler-32 checksum.
;T;[ ;[ ;I"$Returns the adler-32 checksum.
;T;0; @c;!F;"o;#;$T;%i;&i;'@
;(I"jstatic VALUE
rb_zstream_adler(VALUE obj)
{
return rb_uint2inum(get_zstream(obj)->stream.adler);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#finished?;F;[ ;[[@i;T;:finished?;0;[ ;{ ;IC;",Returns true if the stream is finished.;T;[o:YARD::Tags::Tag
:@tag_nameI"return;F:
@textI" ;T;0:@types[I"Boolean;T; @q;[ ;I"-Returns true if the stream is finished.
;T;0; @q;!F;"o;#;$T;%i;&i:@ref_tag_recurse_counti ;'@
;(I"ystatic VALUE
rb_zstream_finished_p(VALUE obj)
{
return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#stream_end?;F;[ ;[[@i;T;:stream_end?;0;[ ;{ ;IC;",Returns true if the stream is finished.;T;[o;2
;3I"return;F;4@|;0;5[@~; @;[ ;@{;0; @;!F;"o;#;$T;%i;&i;6i ;'@
;(I"ystatic VALUE
rb_zstream_finished_p(VALUE obj)
{
return ZSTREAM_IS_FINISHED(get_zstream(obj)) ? Qtrue : Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#closed?;F;[ ;[[@i;T;:closed?;0;[ ;{ ;IC;"*Returns true if the stream is closed.;T;[o;2
;3I"return;F;4@|;0;5[@~; @;[ ;I"+Returns true if the stream is closed.
;T;0; @;!F;"o;#;$T;%i;&i;6i ;'@
;(I"static VALUE
rb_zstream_closed_p(VALUE obj)
{
struct zstream *z;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
return ZSTREAM_IS_READY(z) ? Qfalse : Qtrue;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#ended?;F;[ ;[[@i;T;:ended?;0;[ ;{ ;IC;"*Returns true if the stream is closed.;T;[o;2
;3I"return;F;4@|;0;5[@~; @;[ ;@;0; @;!F;"o;#;$T;%i;&i;6i ;'@
;(I"static VALUE
rb_zstream_closed_p(VALUE obj)
{
struct zstream *z;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
return ZSTREAM_IS_READY(z) ? Qfalse : Qtrue;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#close;F;[ ;[[@i:;T;:
close;0;[ ;{ ;IC;"TCloses the stream. All operations on the closed stream will raise an
exception.
;T;[ ;[ ;I"UCloses the stream. All operations on the closed stream will raise an
exception.
;T;0; @;!F;"o;#;$T;%i6;&i8;'@
;(I"cstatic VALUE
rb_zstream_end(VALUE obj)
{
zstream_end(get_zstream(obj));
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#end;F;[ ;[[@i:;T;;&;0;[ ;{ ;IC;"TCloses the stream. All operations on the closed stream will raise an
exception.
;T;[ ;[ ;@;0; @;!F;"o;#;$T;%i6;&i8;'@
;(I"cstatic VALUE
rb_zstream_end(VALUE obj)
{
zstream_end(get_zstream(obj));
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#reset;F;[ ;[[@iE;T;:
reset;0;[ ;{ ;IC;"_Resets and initializes the stream. All data in both input and output buffer
are discarded.
;T;[ ;[ ;I"`Resets and initializes the stream. All data in both input and output buffer
are discarded.
;T;0; @;!F;"o;#;$T;%iA;&iC;'@
;(I"gstatic VALUE
rb_zstream_reset(VALUE obj)
{
zstream_reset(get_zstream(obj));
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::ZStream#finish;F;[ ;[[@iU;T;:finish;0;[ ;{ ;IC;"Finishes the stream and flushes output buffer. If a block is given each
chunk is yielded to the block until the input buffer has been flushed to
the output buffer.
;T;[o:YARD::Tags::OverloadTag
;3I"
overload;F;40;;<;50;)I"finish;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;[ ;I"@return [String];T;0; @;!F;6i :
@summary0;[ ; @o;=
;3I"
overload;F;40;;<;50;)I"finish;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
chunk;T; @o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"!@yield [chunk]
@return [nil];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Finishes the stream and flushes output buffer. If a block is given each
chunk is yielded to the block until the input buffer has been flushed to
the output buffer.
@overload finish
@return [String]
@overload finish
@yield [chunk]
@return [nil];T;0; @;!F;"o;#;$T;%iL;&iU;'@
;(I"static VALUE
rb_zstream_finish(VALUE obj)
{
struct zstream *z = get_zstream(obj);
zstream_run(z, (Bytef*)"", 0, Z_FINISH);
return zstream_detach_buffer(z);
};T;)I"static VALUE;T;*To;;F;
;;;;I" Zlib::ZStream#flush_next_in;F;[ ;[[@id;T;:flush_next_in;0;[ ;{ ;IC;"
;T;[o;=
;3I"
overload;F;40;;?;50;)I"flush_next_in;T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[ ; @;[ ;I"
@overload flush_next_in;T;0; @;!F;"o;#;$T;%i_;&ia;'@
;(I"static VALUE
rb_zstream_flush_next_in(VALUE obj)
{
struct zstream *z;
VALUE dst;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
dst = zstream_detach_input(z);
return dst;
};T;)I"static VALUE;T;*To;;F;
;;;;I"!Zlib::ZStream#flush_next_out;F;[ ;[[@ix;T;:flush_next_out;0;[ ;{ ;IC;"Flushes output buffer and returns all data in that buffer. If a block is
given each chunk is yielded to the block until the current output buffer
has been flushed.
;T;[o;=
;3I"
overload;F;40;;@;50;)I"flush_next_out;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;[ ;I"@return [String];T;0; @;!F;6i ;>0;[ ; @o;=
;3I"
overload;F;40;;@;50;)I"flush_next_out;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
chunk;T; @o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"!@yield [chunk]
@return [nil];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Flushes output buffer and returns all data in that buffer. If a block is
given each chunk is yielded to the block until the current output buffer
has been flushed.
@overload flush_next_out
@return [String]
@overload flush_next_out
@yield [chunk]
@return [nil];T;0; @;!F;"o;#;$T;%io;&ix;'@
;(I"static VALUE
rb_zstream_flush_next_out(VALUE obj)
{
struct zstream *z;
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
return zstream_detach_buffer(z);
};T;)I"static VALUE;T;*T:@owner@
:@class_mixinsIC;[ ;A@
:@instance_mixinsIC;[ ;A@
:@attributesIC:SymbolHash{:
classIC;E{ :@symbolize_valueT;IC;E{ ;GT;GT:
@aliases{ :@groups[ ;[[@i[@i;T;:ZStream;: ruby;;;[ ;{ ;IC;": Zlib::ZStream is the abstract class for the stream which handles the
compressed data. The operations are defined in the subclasses:
Zlib::Deflate for compression, and Zlib::Inflate for decompression.
An instance of Zlib::ZStream has one stream (struct zstream in the source)
and two variable-length buffers which associated to the input (next_in) of
the stream and the output (next_out) of the stream. In this document,
"input buffer" means the buffer for input, and "output buffer" means the
buffer for output.
Data input into an instance of Zlib::ZStream are temporally stored into
the end of input buffer, and then data in input buffer are processed from
the beginning of the buffer until no more output from the stream is
produced (i.e. until avail_out > 0 after processing). During processing,
output buffer is allocated and expanded automatically to hold all output
data.
Some particular instance methods consume the data in output buffer and
return them as a String.
Here is an ascii art for describing above:
+================ an instance of Zlib::ZStream ================+
|| ||
|| +--------+ +-------+ +--------+ ||
|| +--| output |<---------|zstream|<---------| input |<--+ ||
|| | | buffer | next_out+-------+next_in | buffer | | ||
|| | +--------+ +--------+ | ||
|| | | ||
+===|======================================================|===+
| |
v |
"output data" "input data"
If an error occurs during processing input buffer, an exception which is a
subclass of Zlib::Error is raised. At that time, both input and output
buffer keep their conditions at the time when the error occurs.
== Method Catalogue
Many of the methods in this class are fairly low-level and unlikely to be
of interest to users. In fact, users are unlikely to use this class
directly; rather they will be interested in Zlib::Inflate and
Zlib::Deflate.
The higher level methods are listed below.
- #total_in
- #total_out
- #data_type
- #adler
- #reset
- #finish
- #finished?
- #close
- #closed?;T;[ ;[ ;I"<
Zlib::ZStream is the abstract class for the stream which handles the
compressed data. The operations are defined in the subclasses:
Zlib::Deflate for compression, and Zlib::Inflate for decompression.
An instance of Zlib::ZStream has one stream (struct zstream in the source)
and two variable-length buffers which associated to the input (next_in) of
the stream and the output (next_out) of the stream. In this document,
"input buffer" means the buffer for input, and "output buffer" means the
buffer for output.
Data input into an instance of Zlib::ZStream are temporally stored into
the end of input buffer, and then data in input buffer are processed from
the beginning of the buffer until no more output from the stream is
produced (i.e. until avail_out > 0 after processing). During processing,
output buffer is allocated and expanded automatically to hold all output
data.
Some particular instance methods consume the data in output buffer and
return them as a String.
Here is an ascii art for describing above:
+================ an instance of Zlib::ZStream ================+
|| ||
|| +--------+ +-------+ +--------+ ||
|| +--| output |<---------|zstream|<---------| input |<--+ ||
|| | | buffer | next_out+-------+next_in | buffer | | ||
|| | +--------+ +--------+ | ||
|| | | ||
+===|======================================================|===+
| |
v |
"output data" "input data"
If an error occurs during processing input buffer, an exception which is a
subclass of Zlib::Error is raised. At that time, both input and output
buffer keep their conditions at the time when the error occurs.
== Method Catalogue
Many of the methods in this class are fairly low-level and unlikely to be
of interest to users. In fact, users are unlikely to use this class
directly; rather they will be interested in Zlib::Inflate and
Zlib::Deflate.
The higher level methods are listed below.
- #total_in
- #total_out
- #data_type
- #adler
- #reset
- #finish
- #finished?
- #close
- #closed?
;T;0; @
;!F;"o;#;$T;%i;&i2;6i ;'o:YARD::CodeObjects::Proxy:@orignamespace0:@origname0:
@imethod0;: Zlib;'@: @obj@:
@type0;I"Zlib::ZStream;F:@superclasso;L;M0;N0;O0;:Object;'@;Qo;
;IC;[Ao;;F;
;;;;I"Object#extend;F;[[I"
*args;T0;[[I"eval.c;Ti;T;:extend;0;[ ;{ ;IC;"sAdds to _obj_ the instance methods from each module given as a
parameter.
module Mod
def hello
"Hello from Mod.\n"
end
end
class Klass
def hello
"Hello from Klass.\n"
end
end
k = Klass.new
k.hello #=> "Hello from Klass.\n"
k.extend(Mod) #=> #
k.hello #=> "Hello from Mod.\n"
;T;[o;=
;3I"
overload;F;40;;U;50;)I"extend(module, ...);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @_;[ ;I"@return [Object];T;0; @_;!F;6i ;>0;[ ; @_;[ ;I"Adds to _obj_ the instance methods from each module given as a
parameter.
module Mod
def hello
"Hello from Mod.\n"
end
end
class Klass
def hello
"Hello from Klass.\n"
end
end
k = Klass.new
k.hello #=> "Hello from Klass.\n"
k.extend(Mod) #=> #
k.hello #=> "Hello from Mod.\n"
@overload extend(module, ...)
@return [Object];T;0; @_;!F;"o;#;$T;%i;&i;'@];(I"static VALUE
rb_obj_extend(int argc, VALUE *argv, VALUE obj)
{
int i;
ID id_extend_object, id_extended;
CONST_ID(id_extend_object, "extend_object");
CONST_ID(id_extended, "extended");
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
for (i = 0; i < argc; i++)
Check_Type(argv[i], T_MODULE);
while (argc--) {
rb_funcall(argv[argc], id_extend_object, 1, obj);
rb_funcall(argv[argc], id_extended, 1, obj);
}
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#respond_to?;F;[[@c0;[[I"vm_method.c;Ti;T;:respond_to?;0;[ ;{ ;IC;"Returns +true+ if _obj_ responds to the given method. Private and
protected methods are included in the search only if the optional
second parameter evaluates to +true+.
If the method is not implemented,
as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
false is returned.
If the method is not defined, respond_to_missing?
method is called and the result is returned.
When the method name parameter is given as a string, the string is
converted to a symbol.;T;[o;=
;3I"
overload;F;40;;V;50;)I"+respond_to?(symbol, include_all=false);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @};[ ;I"@return [Boolean];T;0; @};!F;6i ;>0;[[I"symbol;T0[I"include_all;TI"
false;T; @}o;=
;3I"
overload;F;40;;V;50;)I"+respond_to?(string, include_all=false);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @};[ ;I"@return [Boolean];T;0; @};!F;6i ;>0;[[I"string;T0[I"include_all;TI"
false;T; @};[ ;I"pReturns +true+ if _obj_ responds to the given method. Private and
protected methods are included in the search only if the optional
second parameter evaluates to +true+.
If the method is not implemented,
as Process.fork on Windows, File.lchmod on GNU/Linux, etc.,
false is returned.
If the method is not defined, respond_to_missing?
method is called and the result is returned.
When the method name parameter is given as a string, the string is
converted to a symbol.
@overload respond_to?(symbol, include_all=false)
@return [Boolean]
@overload respond_to?(string, include_all=false)
@return [Boolean];T;0; @};!F;"o;#;$T;%i;&i;6i ;'@];(I"static VALUE
obj_respond_to(int argc, VALUE *argv, VALUE obj)
{
VALUE mid, priv;
ID id;
rb_execution_context_t *ec = GET_EC();
rb_scan_args(argc, argv, "11", &mid, &priv);
if (!(id = rb_check_id(&mid))) {
VALUE ret = basic_obj_respond_to_missing(ec, CLASS_OF(obj), obj,
rb_to_symbol(mid), priv);
if (ret == Qundef) ret = Qfalse;
return ret;
}
if (basic_obj_respond_to(ec, obj, id, !RTEST(priv)))
return Qtrue;
return Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#respond_to_missing?;F;[[I"mid;T0[I" priv;T0;[[@i;T;:respond_to_missing?;0;[ ;{ ;IC;"DO NOT USE THIS DIRECTLY.
Hook method to return whether the _obj_ can respond to _id_ method
or not.
When the method name parameter is given as a string, the string is
converted to a symbol.
See #respond_to?, and the example of BasicObject.;T;[o;=
;3I"
overload;F;40;;W;50;)I"-respond_to_missing?(symbol, include_all);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"symbol;T0[I"include_all;T0; @o;=
;3I"
overload;F;40;;W;50;)I"-respond_to_missing?(string, include_all);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"string;T0[I"include_all;T0; @;[ ;I"DO NOT USE THIS DIRECTLY.
Hook method to return whether the _obj_ can respond to _id_ method
or not.
When the method name parameter is given as a string, the string is
converted to a symbol.
See #respond_to?, and the example of BasicObject.
@overload respond_to_missing?(symbol, include_all)
@return [Boolean]
@overload respond_to_missing?(string, include_all)
@return [Boolean];T;0; @;!F;"o;#;$T;%i;&i;6i ;'@];(I"astatic VALUE
obj_respond_to_missing(VALUE obj, VALUE mid, VALUE priv)
{
return Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#to_enum;F;[[@c0;[[I"enumerator.c;Ti_;T;:to_enum;0;[ ;{ ;IC;"{Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any. What was _yielded_ by method becomes
values of enumerator.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
# String#split in block form is more memory-effective:
very_large_string.split("|") { |chunk| return chunk if chunk.include?('DATE') }
# This could be rewritten more idiomatically with to_enum:
very_large_string.to_enum(:split, "|").lazy.grep(/DATE/).first
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
;T;[ o;=
;3I"
overload;F;40;;X;50;)I"#to_enum(method = :each, *args);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @;[ ;I"@return [Enumerator];T;0; @;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @o;=
;3I"
overload;F;40;:
enum_for;50;)I"$enum_for(method = :each, *args);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @;[ ;I"@return [Enumerator];T;0; @;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @o;=
;3I"
overload;F;40;;X;50;)I"#to_enum(method = :each, *args);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
*args;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @;[ ;I"(@yield [*args]
@return [Enumerator];T;0; @;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @o;=
;3I"
overload;F;40;;Y;50;)I"$enum_for(method = :each, *args);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
*args;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @;[ ;I"(@yield [*args]
@return [Enumerator];T;0; @;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @;[ ;I"Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any. What was _yielded_ by method becomes
values of enumerator.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
# String#split in block form is more memory-effective:
very_large_string.split("|") { |chunk| return chunk if chunk.include?('DATE') }
# This could be rewritten more idiomatically with to_enum:
very_large_string.to_enum(:split, "|").lazy.grep(/DATE/).first
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
@overload to_enum(method = :each, *args)
@return [Enumerator]
@overload enum_for(method = :each, *args)
@return [Enumerator]
@overload to_enum(method = :each, *args)
@yield [*args]
@return [Enumerator]
@overload enum_for(method = :each, *args)
@yield [*args]
@return [Enumerator];T;0; @;!F;"o;#;$T;%i";&ib;'@];(I"Qstatic VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#enum_for;F;[[@c0;[[@i_;T;;Y;0;[ ;{ ;IC;"{Creates a new Enumerator which will enumerate by calling +method+ on
+obj+, passing +args+ if any. What was _yielded_ by method becomes
values of enumerator.
If a block is given, it will be used to calculate the size of
the enumerator without the need to iterate it (see Enumerator#size).
=== Examples
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b }
# => 120
# => 121
# => 122
# protect an array from being modified by some_method
a = [1, 2, 3]
some_method(a.to_enum)
# String#split in block form is more memory-effective:
very_large_string.split("|") { |chunk| return chunk if chunk.include?('DATE') }
# This could be rewritten more idiomatically with to_enum:
very_large_string.to_enum(:split, "|").lazy.grep(/DATE/).first
It is typical to call to_enum when defining methods for
a generic Enumerable, in case no block is passed.
Here is such an example, with parameter passing and a sizing block:
module Enumerable
# a generic method to repeat the values of any enumerable
def repeat(n)
raise ArgumentError, "#{n} is negative!" if n < 0
unless block_given?
return to_enum(__method__, n) do # __method__ is :repeat here
sz = size # Call size and multiply by n...
sz * n if sz # but return nil if size itself is nil
end
end
each do |*val|
n.times { yield *val }
end
end
end
%i[hello world].repeat(2) { |w| puts w }
# => Prints 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => returns an Enumerator when called without a block
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
;T;[ o;=
;3I"
overload;F;40;;X;50;)I"#to_enum(method = :each, *args);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @G;[ ;I"@return [Enumerator];T;0; @G;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @Go;=
;3I"
overload;F;40;;Y;50;)I"$enum_for(method = :each, *args);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @G;[ ;I"@return [Enumerator];T;0; @G;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @Go;=
;3I"
overload;F;40;;X;50;)I"#to_enum(method = :each, *args);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
*args;T; @Go;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @G;[ ;I"(@yield [*args]
@return [Enumerator];T;0; @G;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @Go;=
;3I"
overload;F;40;;Y;50;)I"$enum_for(method = :each, *args);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"
*args;T; @Go;2
;3I"return;F;4I" ;T;0;5[I"Enumerator;T; @G;[ ;I"(@yield [*args]
@return [Enumerator];T;0; @G;!F;6i ;>0;[[I"method;TI"
:each;T[I"
*args;T0; @G;[ ;@C;0; @G;!F;"o;#;$T;%i";&ib;'@];(I"Qstatic VALUE
obj_to_enum(int argc, VALUE *argv, VALUE obj)
{
VALUE enumerator, meth = sym_each;
if (argc > 0) {
--argc;
meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#display;F;[[@c0;[[I" io.c;Ti;T;:display;0;[ ;{ ;IC;"Prints obj on the given port (default $>
).
Equivalent to:
def display(port=$>)
port.write self
nil
end
For example:
1.display
"cat".display
[ 4, 5, 6 ].display
puts
produces:
1cat[4, 5, 6]
;T;[o;=
;3I"
overload;F;40;;Z;50;)I"display(port=$>);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I" port;TI"$>;T; @;[ ;I"*Prints obj on the given port (default $>
).
Equivalent to:
def display(port=$>)
port.write self
nil
end
For example:
1.display
"cat".display
[ 4, 5, 6 ].display
puts
produces:
1cat[4, 5, 6]
@overload display(port=$>)
@return [nil];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"static VALUE
rb_obj_display(int argc, VALUE *argv, VALUE self)
{
VALUE out;
out = (!rb_check_arity(argc, 0, 1) ? rb_stdout : argv[0]);
rb_io_write(out, self);
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#nil?;F;[ ;[[I"
object.c;TiG;T;: nil?;0;[ ;{ ;IC;"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true;T;[o;=
;3I"
overload;F;40;;[;50;)I" nil?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Only the object nil responds true
to nil?
.
Object.new.nil? #=> false
nil.nil? #=> true
@overload nil?
@return [Boolean];T;0; @;!F;"o;#;$T;%i<;&iC;6i ;'@];(I"HMJIT_FUNC_EXPORTED VALUE
rb_false(VALUE obj)
{
return Qfalse;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"Object#===;F;[[I" obj2;T0;[[@i;T;:===;0;[ ;{ ;IC;"Case Equality -- For class Object, effectively the same as calling
#==
, but typically overridden by descendants to provide
meaningful semantics in +case+ statements.
;T;[o;=
;3I"
overload;F;40;;\;50;)I"===(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @;[ ;I"Case Equality -- For class Object, effectively the same as calling
#==
, but typically overridden by descendants to provide
meaningful semantics in +case+ statements.
@overload ===(other)
@return [Boolean];T;0; @;!F;"o;#;$T;%i|;&i~;'@];(I"VALUE
rb_equal(VALUE obj1, VALUE obj2)
{
VALUE result;
if (obj1 == obj2) return Qtrue;
result = rb_equal_opt(obj1, obj2);
if (result == Qundef) {
result = rb_funcall(obj1, id_eq, 1, obj2);
}
if (RTEST(result)) return Qtrue;
return Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#=~;F;[[I" obj2;T0;[[@iX;T;:=~;0;[ ;{ ;IC;"qThis method is deprecated.
This is not only unuseful but also troublesome because it
may hide a type error.
;T;[o;=
;3I"
overload;F;40;;];50;)I"=~(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"
other;T0; @;[ ;I"This method is deprecated.
This is not only unuseful but also troublesome because it
may hide a type error.
@overload =~(other)
@return [nil];T;0; @;!F;"o;#;$T;%iN;&iU;'@];(I"static VALUE
rb_obj_match(VALUE obj1, VALUE obj2)
{
if (rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) {
rb_warn("deprecated Object#=~ is called on %"PRIsVALUE
"; it always returns nil", rb_obj_class(obj1));
}
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#!~;F;[[I" obj2;T0;[[@ij;T;:!~;0;[ ;{ ;IC;"\Returns true if two objects do not match (using the =~
method), otherwise false.
;T;[o;=
;3I"
overload;F;40;;^;50;)I"!~(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @!;[ ;I"@return [Boolean];T;0; @!;!F;6i ;>0;[[I"
other;T0; @!;[ ;I"Returns true if two objects do not match (using the =~
method), otherwise false.
@overload !~(other)
@return [Boolean];T;0; @!;!F;"o;#;$T;%ib;&ig;'@];(I"static VALUE
rb_obj_not_match(VALUE obj1, VALUE obj2)
{
VALUE result = rb_funcall(obj1, id_match, 1, obj2);
return RTEST(result) ? Qfalse : Qtrue;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#eql?;F;[[I" obj2;T0;[[@i;T;: eql?;0;[ ;{ ;IC;"Equality --- At the Object level, #== returns true
only if +obj+ and +other+ are the same object. Typically, this
method is overridden in descendant classes to provide
class-specific meaning.
Unlike #==, the #equal? method should never be overridden by
subclasses as it is used to determine object identity (that is,
a.equal?(b)
if and only if a
is the same
object as b
):
obj = "a"
other = obj.dup
obj == other #=> true
obj.equal? other #=> false
obj.equal? obj #=> true
The #eql? method returns true
if +obj+ and +other+
refer to the same hash key. This is used by Hash to test members
for equality. For any pair of objects where #eql? returns +true+,
the #hash value of both objects must be equal. So any subclass
that overrides #eql? should also override #hash appropriately.
For objects of class Object, #eql? is synonymous
with #==. Subclasses normally continue this tradition by aliasing
#eql? to their overridden #== method, but there are exceptions.
Numeric types, for example, perform type conversion across #==,
but not across #eql?, so:
1 == 1.0 #=> true
1.eql? 1.0 #=> false;T;[o;=
;3I"
overload;F;40;:==;50;)I"==(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @@;[ ;I"@return [Boolean];T;0; @@;!F;6i ;>0;[[I"
other;T0; @@o;=
;3I"
overload;F;40;:equal?;50;)I"equal?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @@;[ ;I"@return [Boolean];T;0; @@;!F;6i ;>0;[[I"
other;T0; @@o;=
;3I"
overload;F;40;;_;50;)I"eql?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @@;[ ;I"@return [Boolean];T;0; @@;!F;6i ;>0;[[I"
other;T0; @@;[ ;I"*Equality --- At the Object level, #== returns true
only if +obj+ and +other+ are the same object. Typically, this
method is overridden in descendant classes to provide
class-specific meaning.
Unlike #==, the #equal? method should never be overridden by
subclasses as it is used to determine object identity (that is,
a.equal?(b)
if and only if a
is the same
object as b
):
obj = "a"
other = obj.dup
obj == other #=> true
obj.equal? other #=> false
obj.equal? obj #=> true
The #eql? method returns true
if +obj+ and +other+
refer to the same hash key. This is used by Hash to test members
for equality. For any pair of objects where #eql? returns +true+,
the #hash value of both objects must be equal. So any subclass
that overrides #eql? should also override #hash appropriately.
For objects of class Object, #eql? is synonymous
with #==. Subclasses normally continue this tradition by aliasing
#eql? to their overridden #== method, but there are exceptions.
Numeric types, for example, perform type conversion across #==,
but not across #eql?, so:
1 == 1.0 #=> true
1.eql? 1.0 #=> false
@overload ==(other)
@return [Boolean]
@overload equal?(other)
@return [Boolean]
@overload eql?(other)
@return [Boolean];T;0; @@;!F;"o;#;$T;%i;&i;6i ;'@];(I"}MJIT_FUNC_EXPORTED VALUE
rb_obj_equal(VALUE obj1, VALUE obj2)
{
if (obj1 == obj2) return Qtrue;
return Qfalse;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"Object#hash;F;[ ;[[@i;T;: hash;0;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @};'@];(I""VALUE rb_obj_hash(VALUE obj);;T;)I""VALUE rb_obj_hash(VALUE obj);;T;*To;;F;
;;;;I"Object#<=>;F;[[I" obj2;T0;[[@i;T;:<=>;0;[ ;{ ;IC;"%Returns 0 if +obj+ and +other+ are the same object
or obj == other
, otherwise nil.
The #<=> is used by various methods to compare objects, for example
Enumerable#sort, Enumerable#max etc.
Your implementation of #<=> should return one of the following values: -1, 0,
1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
1 means self is bigger than other. Nil means the two values could not be
compared.
When you define #<=>, you can include Comparable to gain the
methods #<=, #<, #==, #>=, #> and #between?.
;T;[o;=
;3I"
overload;F;40;;c;50;)I"<=>(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"0;TI"nil;T; @;[ ;I"@return [0, nil];T;0; @;!F;6i ;>0;[[I"
other;T0; @;[ ;I"OReturns 0 if +obj+ and +other+ are the same object
or obj == other
, otherwise nil.
The #<=> is used by various methods to compare objects, for example
Enumerable#sort, Enumerable#max etc.
Your implementation of #<=> should return one of the following values: -1, 0,
1 or nil. -1 means self is smaller than other. 0 means self is equal to other.
1 means self is bigger than other. Nil means the two values could not be
compared.
When you define #<=>, you can include Comparable to gain the
methods #<=, #<, #==, #>=, #> and #between?.
@overload <=>(other)
@return [0, nil];T;0; @;!F;"o;#;$T;%ir;&i;'@];(I"static VALUE
rb_obj_cmp(VALUE obj1, VALUE obj2)
{
if (obj1 == obj2 || rb_equal(obj1, obj2))
return INT2FIX(0);
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#class;F;[ ;[[@i;T;;F;0;[ ;{ ;IC;"Returns the class of obj. This method must always be called
with an explicit receiver, as #class is also a reserved word in
Ruby.
1.class #=> Integer
self.class #=> Object
;T;[o;=
;3I"
overload;F;40;;F;50;)I"
class;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Class;T; @;[ ;I"@return [Class];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns the class of obj. This method must always be called
with an explicit receiver, as #class is also a reserved word in
Ruby.
1.class #=> Integer
self.class #=> Object
@overload class
@return [Class];T;0; @;!F;"o;#;$T;%i
;&i;'@];(I"OVALUE
rb_obj_class(VALUE obj)
{
return rb_class_real(CLASS_OF(obj));
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#singleton_class;F;[ ;[[@i4;T;:singleton_class;0;[ ;{ ;IC;"Returns the singleton class of obj. This method creates
a new singleton class if obj does not have one.
If obj is nil
, true
, or
false
, it returns NilClass, TrueClass, or FalseClass,
respectively.
If obj is an Integer, a Float or a Symbol, it raises a TypeError.
Object.new.singleton_class #=> #>
String.singleton_class #=> #
nil.singleton_class #=> NilClass
;T;[o;=
;3I"
overload;F;40;;d;50;)I"singleton_class;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Class;T; @;[ ;I"@return [Class];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns the singleton class of obj. This method creates
a new singleton class if obj does not have one.
If obj is nil
, true
, or
false
, it returns NilClass, TrueClass, or FalseClass,
respectively.
If obj is an Integer, a Float or a Symbol, it raises a TypeError.
Object.new.singleton_class #=> #>
String.singleton_class #=> #
nil.singleton_class #=> NilClass
@overload singleton_class
@return [Class];T;0; @;!F;"o;#;$T;%i#;&i1;'@];(I"[static VALUE
rb_obj_singleton_class(VALUE obj)
{
return rb_singleton_class(obj);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#clone;F;[[@c0;[[@i;T;:
clone;0;[ ;{ ;IC;"Produces a shallow copy of obj---the instance variables of
obj are copied, but not the objects they reference.
#clone copies the frozen (unless +:freeze+ keyword argument is
given with a false value) state of obj. See
also the discussion under Object#dup.
class Klass
attr_accessor :str
end
s1 = Klass.new #=> #
s1.str = "Hello" #=> "Hello"
s2 = s1.clone #=> #
s2.str[1,4] = "i" #=> "i"
s1.inspect #=> "#"
s2.inspect #=> "#"
This method may have class-specific behavior. If so, that
behavior will be documented under the #+initialize_copy+ method of
the class.
;T;[o;=
;3I"
overload;F;40;;e;50;)I"clone(freeze: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"freeze:;TI" true;T; @;[ ;I")Produces a shallow copy of obj---the instance variables of
obj are copied, but not the objects they reference.
#clone copies the frozen (unless +:freeze+ keyword argument is
given with a false value) state of obj. See
also the discussion under Object#dup.
class Klass
attr_accessor :str
end
s1 = Klass.new #=> #
s1.str = "Hello" #=> "Hello"
s2 = s1.clone #=> #
s2.str[1,4] = "i" #=> "i"
s1.inspect #=> "#"
s2.inspect #=> "#"
This method may have class-specific behavior. If so, that
behavior will be documented under the #+initialize_copy+ method of
the class.
@overload clone(freeze: true)
@return [Object];T;0; @;!F;"o;#;$T;%i{;&i;'@];(I"static VALUE
rb_obj_clone2(int argc, VALUE *argv, VALUE obj)
{
int kwfreeze = freeze_opt(argc, argv);
if (!special_object_p(obj))
return mutable_obj_clone(obj, kwfreeze);
return immutable_obj_clone(obj, kwfreeze);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#dup;F;[ ;[[@i;T;:dup;0;[ ;{ ;IC;"Produces a shallow copy of obj---the instance variables of
obj are copied, but not the objects they reference.
This method may have class-specific behavior. If so, that
behavior will be documented under the #+initialize_copy+ method of
the class.
=== on dup vs clone
In general, #clone and #dup may have different semantics in
descendant classes. While #clone is used to duplicate an object,
including its internal state, #dup typically uses the class of the
descendant object to create the new instance.
When using #dup, any modules that the object has been extended with will not
be copied.
class Klass
attr_accessor :str
end
module Foo
def foo; 'foo'; end
end
s1 = Klass.new #=> #
s1.extend(Foo) #=> #
s1.foo #=> "foo"
s2 = s1.clone #=> #
s2.foo #=> "foo"
s3 = s1.dup #=> #
s3.foo #=> NoMethodError: undefined method `foo' for #
;T;[o;=
;3I"
overload;F;40;;f;50;)I"dup;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Produces a shallow copy of obj---the instance variables of
obj are copied, but not the objects they reference.
This method may have class-specific behavior. If so, that
behavior will be documented under the #+initialize_copy+ method of
the class.
=== on dup vs clone
In general, #clone and #dup may have different semantics in
descendant classes. While #clone is used to duplicate an object,
including its internal state, #dup typically uses the class of the
descendant object to create the new instance.
When using #dup, any modules that the object has been extended with will not
be copied.
class Klass
attr_accessor :str
end
module Foo
def foo; 'foo'; end
end
s1 = Klass.new #=> #
s1.extend(Foo) #=> #
s1.foo #=> "foo"
s2 = s1.clone #=> #
s2.foo #=> "foo"
s3 = s1.dup #=> #
s3.foo #=> NoMethodError: undefined method `foo' for #
@overload dup
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_dup(VALUE obj)
{
VALUE dup;
if (special_object_p(obj)) {
return obj;
}
dup = rb_obj_alloc(rb_obj_class(obj));
init_copy(dup, obj);
rb_funcall(dup, id_init_dup, 1, obj);
return dup;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#itself;F;[ ;[[@i,;T;:itself;0;[ ;{ ;IC;"mReturns the receiver.
string = "my string"
string.itself.object_id == string.object_id #=> true
;T;[o;=
;3I"
overload;F;40;;g;50;)I"itself;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns the receiver.
string = "my string"
string.itself.object_id == string.object_id #=> true
@overload itself
@return [Object];T;0; @;!F;"o;#;$T;%i!;&i);'@];(I">static VALUE
rb_obj_itself(VALUE obj)
{
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#yield_self;F;[ ;[[@iV;T;:yield_self;0;[ ;{ ;IC;"Yields self to the block and returns the result of the block.
3.next.then {|x| x**x }.to_s #=> "256"
"my string".yield_self {|s| s.upcase } #=> "MY STRING"
Good usage for +then+ is value piping in method chains:
require 'open-uri'
require 'json'
construct_url(arguments).
then {|url| open(url).read }.
then {|response| JSON.parse(response) }
When called without block, the method returns +Enumerator+,
which can be used, for example, for conditional
circuit-breaking:
# meets condition, no-op
1.then.detect(&:odd?) # => 1
# does not meet condition, drop value
2.then.detect(&:odd?) # => nil
;T;[o;=
;3I"
overload;F;40;: then;50;)I" then;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"x;T; @4o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @4;[ ;I" @yield [x]
@return [Object];T;0; @4;!F;6i ;>0;[ ; @4o;=
;3I"
overload;F;40;;h;50;)I"yield_self;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"x;T; @4o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @4;[ ;I" @yield [x]
@return [Object];T;0; @4;!F;6i ;>0;[ ; @4;[ ;I"Yields self to the block and returns the result of the block.
3.next.then {|x| x**x }.to_s #=> "256"
"my string".yield_self {|s| s.upcase } #=> "MY STRING"
Good usage for +then+ is value piping in method chains:
require 'open-uri'
require 'json'
construct_url(arguments).
then {|url| open(url).read }.
then {|response| JSON.parse(response) }
When called without block, the method returns +Enumerator+,
which can be used, for example, for conditional
circuit-breaking:
# meets condition, no-op
1.then.detect(&:odd?) # => 1
# does not meet condition, drop value
2.then.detect(&:odd?) # => nil
@overload then
@yield [x]
@return [Object]
@overload yield_self
@yield [x]
@return [Object];T;0; @4;!F;"o;#;$T;%i8;&iV;'@];(I"static VALUE
rb_obj_yield_self(VALUE obj)
{
RETURN_SIZED_ENUMERATOR(obj, 0, 0, rb_obj_size);
return rb_yield_values2(1, &obj);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#then;F;[ ;[[@iV;T;;i;0;[ ;{ ;IC;"Yields self to the block and returns the result of the block.
3.next.then {|x| x**x }.to_s #=> "256"
"my string".yield_self {|s| s.upcase } #=> "MY STRING"
Good usage for +then+ is value piping in method chains:
require 'open-uri'
require 'json'
construct_url(arguments).
then {|url| open(url).read }.
then {|response| JSON.parse(response) }
When called without block, the method returns +Enumerator+,
which can be used, for example, for conditional
circuit-breaking:
# meets condition, no-op
1.then.detect(&:odd?) # => 1
# does not meet condition, drop value
2.then.detect(&:odd?) # => nil
;T;[o;=
;3I"
overload;F;40;;i;50;)I" then;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"x;T; @fo;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @f;[ ;I" @yield [x]
@return [Object];T;0; @f;!F;6i ;>0;[ ; @fo;=
;3I"
overload;F;40;;h;50;)I"yield_self;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"x;T; @fo;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @f;[ ;I" @yield [x]
@return [Object];T;0; @f;!F;6i ;>0;[ ; @f;[ ;@b;0; @f;!F;"o;#;$T;%i8;&iV;'@];(I"static VALUE
rb_obj_yield_self(VALUE obj)
{
RETURN_SIZED_ENUMERATOR(obj, 0, 0, rb_obj_size);
return rb_yield_values2(1, &obj);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#initialize_copy;F;[[I" orig;T0;[[@ie;T;:initialize_copy;0;[ ;{ ;IC;":nodoc:
;T;[ ;[ ;I":nodoc:
;T;0; @;!F;"o;#;$T;%i];&i_;'@];(I"VALUE
rb_obj_init_copy(VALUE obj, VALUE orig)
{
if (obj == orig) return obj;
rb_check_frozen(obj);
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
rb_raise(rb_eTypeError, "initialize_copy should take same class object");
}
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#initialize_dup;F;[[I" orig;T0;[[@iy;T;:initialize_dup;0;[ ;{ ;IC;"!
:nodoc:
;T;[ ;[ ;I"!
:nodoc:
;T;0; @;!F;"o;#;$T;%ip;&is;'@];(I"wVALUE
rb_obj_init_dup_clone(VALUE obj, VALUE orig)
{
rb_funcall(obj, id_init_copy, 1, orig);
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#initialize_clone;F;[[I" orig;T0;[[@iy;T;:initialize_clone;0;[ ;{ ;IC;"!
:nodoc:
;T;[ ;[ ;@;0; @;!F;"o;#;$T;%ip;&is;'@];(I"wVALUE
rb_obj_init_dup_clone(VALUE obj, VALUE orig)
{
rb_funcall(obj, id_init_copy, 1, orig);
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#taint;F;[ ;[[@i;T;:
taint;0;[ ;{ ;IC;"OReturns object. This method is deprecated and will be removed in Ruby 3.2.
;T;[o;=
;3I"
overload;F;40;;m;50;)I"
taint;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"tReturns object. This method is deprecated and will be removed in Ruby 3.2.
@overload taint
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_taint(VALUE obj)
{
rb_warning("Object#taint is deprecated and will be removed in Ruby 3.2.");
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#tainted?;F;[ ;[[@i;T;:
tainted?;0;[ ;{ ;IC;"OReturns false. This method is deprecated and will be removed in Ruby 3.2.;T;[o;=
;3I"
overload;F;40;;n;50;)I"
tainted?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
false;T; @;[ ;I"@return [false];T;0; @;!F;6i ;>0;[ ; @;[ ;I"vReturns false. This method is deprecated and will be removed in Ruby 3.2.
@overload tainted?
@return [false];T;0; @;!F;"o;#;$T;%i;&i;6i ;'@];(I"VALUE
rb_obj_tainted(VALUE obj)
{
rb_warning("Object#tainted? is deprecated and will be removed in Ruby 3.2.");
return Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#untaint;F;[ ;[[@i;T;:untaint;0;[ ;{ ;IC;"OReturns object. This method is deprecated and will be removed in Ruby 3.2.
;T;[o;=
;3I"
overload;F;40;;o;50;)I"untaint;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"vReturns object. This method is deprecated and will be removed in Ruby 3.2.
@overload untaint
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_untaint(VALUE obj)
{
rb_warning("Object#untaint is deprecated and will be removed in Ruby 3.2.");
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#untrust;F;[ ;[[@i;T;:untrust;0;[ ;{ ;IC;"OReturns object. This method is deprecated and will be removed in Ruby 3.2.
;T;[o;=
;3I"
overload;F;40;;p;50;)I"untrust;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"vReturns object. This method is deprecated and will be removed in Ruby 3.2.
@overload untrust
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_untrust(VALUE obj)
{
rb_warning("Object#untrust is deprecated and will be removed in Ruby 3.2.");
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#untrusted?;F;[ ;[[@i;T;:untrusted?;0;[ ;{ ;IC;"OReturns false. This method is deprecated and will be removed in Ruby 3.2.;T;[o;=
;3I"
overload;F;40;;q;50;)I"untrusted?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
false;T; @2;[ ;I"@return [false];T;0; @2;!F;6i ;>0;[ ; @2;[ ;I"xReturns false. This method is deprecated and will be removed in Ruby 3.2.
@overload untrusted?
@return [false];T;0; @2;!F;"o;#;$T;%i;&i;6i ;'@];(I"VALUE
rb_obj_untrusted(VALUE obj)
{
rb_warning("Object#untrusted? is deprecated and will be removed in Ruby 3.2.");
return Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#trust;F;[ ;[[@i;T;:
trust;0;[ ;{ ;IC;"OReturns object. This method is deprecated and will be removed in Ruby 3.2.
;T;[o;=
;3I"
overload;F;40;;r;50;)I"
trust;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @M;[ ;I"@return [Object];T;0; @M;!F;6i ;>0;[ ; @M;[ ;I"tReturns object. This method is deprecated and will be removed in Ruby 3.2.
@overload trust
@return [Object];T;0; @M;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_trust(VALUE obj)
{
rb_warning("Object#trust is deprecated and will be removed in Ruby 3.2.");
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#freeze;F;[ ;[[@i;T;:freeze;0;[ ;{ ;IC;"Prevents further modifications to obj. A
RuntimeError will be raised if modification is attempted.
There is no way to unfreeze a frozen object. See also
Object#frozen?.
This method returns self.
a = [ "a", "b", "c" ]
a.freeze
a << "z"
produces:
prog.rb:3:in `<<': can't modify frozen Array (FrozenError)
from prog.rb:3
Objects of the following classes are always frozen: Integer,
Float, Symbol.
;T;[o;=
;3I"
overload;F;40;;s;50;)I"freeze;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @h;[ ;I"@return [Object];T;0; @h;!F;6i ;>0;[ ; @h;[ ;I"Prevents further modifications to obj. A
RuntimeError will be raised if modification is attempted.
There is no way to unfreeze a frozen object. See also
Object#frozen?.
This method returns self.
a = [ "a", "b", "c" ]
a.freeze
a << "z"
produces:
prog.rb:3:in `<<': can't modify frozen Array (FrozenError)
from prog.rb:3
Objects of the following classes are always frozen: Integer,
Float, Symbol.
@overload freeze
@return [Object];T;0; @h;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_freeze(VALUE obj)
{
if (!OBJ_FROZEN(obj)) {
OBJ_FREEZE(obj);
if (SPECIAL_CONST_P(obj)) {
rb_bug("special consts should be frozen.");
}
}
return obj;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#frozen?;F;[ ;[[@i#;T;:frozen?;0;[ ;{ ;IC;"}Returns the freeze status of obj.
a = [ "a", "b", "c" ]
a.freeze #=> ["a", "b", "c"]
a.frozen? #=> true;T;[o;=
;3I"
overload;F;40;;t;50;)I"frozen?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns the freeze status of obj.
a = [ "a", "b", "c" ]
a.freeze #=> ["a", "b", "c"]
a.frozen? #=> true
@overload frozen?
@return [Boolean];T;0; @;!F;"o;#;$T;%i;&i;6i ;'@];(I"VVALUE
rb_obj_frozen_p(VALUE obj)
{
return OBJ_FROZEN(obj) ? Qtrue : Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#to_s;F;[ ;[[@i;T;: to_s;0;[ ;{ ;IC;"Returns a string representing obj. The default #to_s prints
the object's class and an encoding of the object id. As a special
case, the top-level object that is the initial execution context
of Ruby programs returns ``main''.
;T;[o;=
;3I"
overload;F;40;;u;50;)I" to_s;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;[ ;I"@return [String];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns a string representing obj. The default #to_s prints
the object's class and an encoding of the object id. As a special
case, the top-level object that is the initial execution context
of Ruby programs returns ``main''.
@overload to_s
@return [String];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_any_to_s(VALUE obj)
{
VALUE str;
VALUE cname = rb_class_name(CLASS_OF(obj));
str = rb_sprintf("#<%"PRIsVALUE":%p>", cname, (void*)obj);
return str;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#inspect;F;[ ;[[@i;T;:inspect;0;[ ;{ ;IC;"2Returns a string containing a human-readable representation of obj.
The default #inspect shows the object's class name, an encoding of
the object id, and a list of the instance variables and their
values (by calling #inspect on each of them). User defined classes
should override this method to provide a better representation of
obj. When overriding this method, it should return a string
whose encoding is compatible with the default external encoding.
[ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
class Foo
end
Foo.new.inspect #=> "#"
class Bar
def initialize
@bar = 1
end
end
Bar.new.inspect #=> "#"
;T;[o;=
;3I"
overload;F;40;;v;50;)I"inspect;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;[ ;I"@return [String];T;0; @;!F;6i ;>0;[ ; @;[ ;I"YReturns a string containing a human-readable representation of obj.
The default #inspect shows the object's class name, an encoding of
the object id, and a list of the instance variables and their
values (by calling #inspect on each of them). User defined classes
should override this method to provide a better representation of
obj. When overriding this method, it should return a string
whose encoding is compatible with the default external encoding.
[ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]"
Time.new.inspect #=> "2008-03-08 19:43:39 +0900"
class Foo
end
Foo.new.inspect #=> "#"
class Bar
def initialize
@bar = 1
end
end
Bar.new.inspect #=> "#"
@overload inspect
@return [String];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"static VALUE
rb_obj_inspect(VALUE obj)
{
if (rb_ivar_count(obj) > 0) {
VALUE str;
VALUE c = rb_class_name(CLASS_OF(obj));
str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void*)obj);
return rb_exec_recursive(inspect_obj, obj, str);
}
else {
return rb_any_to_s(obj);
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#methods;F;[[@c0;[[I"class.c;Tib;T;:methods;0;[ ;{ ;IC;",Returns a list of the names of public and protected methods of
obj. This will include all the methods accessible in
obj's ancestors.
If the optional parameter is false
, it
returns an array of obj's public and protected singleton methods,
the array will not include methods in modules included in obj.
class Klass
def klass_method()
end
end
k = Klass.new
k.methods[0..9] #=> [:klass_method, :nil?, :===,
# :==~, :!, :eql?
# :hash, :<=>, :class, :singleton_class]
k.methods.length #=> 56
k.methods(false) #=> []
def k.singleton_method; end
k.methods(false) #=> [:singleton_method]
module M123; def m123; end end
k.extend M123
k.methods(false) #=> [:singleton_method]
;T;[o;=
;3I"
overload;F;40;;w;50;)I"methods(regular=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @;[ ;I"@return [Array];T;0; @;!F;6i ;>0;[[I"regular;TI" true;T; @;[ ;I"`Returns a list of the names of public and protected methods of
obj. This will include all the methods accessible in
obj's ancestors.
If the optional parameter is false
, it
returns an array of obj's public and protected singleton methods,
the array will not include methods in modules included in obj.
class Klass
def klass_method()
end
end
k = Klass.new
k.methods[0..9] #=> [:klass_method, :nil?, :===,
# :==~, :!, :eql?
# :hash, :<=>, :class, :singleton_class]
k.methods.length #=> 56
k.methods(false) #=> []
def k.singleton_method; end
k.methods(false) #=> [:singleton_method]
module M123; def m123; end end
k.extend M123
k.methods(false) #=> [:singleton_method]
@overload methods(regular=true)
@return [Array];T;0; @;!F;"o;#;$T;%iD;&i_;'@];(I"VALUE
rb_obj_methods(int argc, const VALUE *argv, VALUE obj)
{
rb_check_arity(argc, 0, 1);
if (argc > 0 && !RTEST(argv[0])) {
return rb_obj_singleton_methods(argc, argv, obj);
}
return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#singleton_methods;F;[[@c0;[[@i;T;:singleton_methods;0;[ ;{ ;IC;"JReturns an array of the names of singleton methods for obj.
If the optional all parameter is true, the list will include
methods in modules included in obj.
Only public and protected singleton methods are returned.
module Other
def three() end
end
class Single
def Single.four() end
end
a = Single.new
def a.one()
end
class << a
include Other
def two()
end
end
Single.singleton_methods #=> [:four]
a.singleton_methods(false) #=> [:two, :one]
a.singleton_methods #=> [:two, :one, :three]
;T;[o;=
;3I"
overload;F;40;;x;50;)I" singleton_methods(all=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @;[ ;I"@return [Array];T;0; @;!F;6i ;>0;[[I"all;TI" true;T; @;[ ;I"Returns an array of the names of singleton methods for obj.
If the optional all parameter is true, the list will include
methods in modules included in obj.
Only public and protected singleton methods are returned.
module Other
def three() end
end
class Single
def Single.four() end
end
a = Single.new
def a.one()
end
class << a
include Other
def two()
end
end
Single.singleton_methods #=> [:four]
a.singleton_methods(false) #=> [:two, :one]
a.singleton_methods #=> [:two, :one, :three]
@overload singleton_methods(all=true)
@return [Array];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"(VALUE
rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
{
VALUE ary, klass, origin;
struct method_entry_arg me_arg;
struct rb_id_table *mtbl;
int recur = TRUE;
if (rb_check_arity(argc, 0, 1)) recur = RTEST(argv[0]);
if (RB_TYPE_P(obj, T_CLASS) && FL_TEST(obj, FL_SINGLETON)) {
rb_singleton_class(obj);
}
klass = CLASS_OF(obj);
origin = RCLASS_ORIGIN(klass);
me_arg.list = st_init_numtable();
me_arg.recur = recur;
if (klass && FL_TEST(klass, FL_SINGLETON)) {
if ((mtbl = RCLASS_M_TBL(origin)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
klass = RCLASS_SUPER(klass);
}
if (recur) {
while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
klass = RCLASS_SUPER(klass);
}
}
ary = rb_ary_new2(me_arg.list->num_entries);
st_foreach(me_arg.list, ins_methods_i, ary);
st_free_table(me_arg.list);
return ary;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#protected_methods;F;[[@c0;[[@iu;T;:protected_methods;0;[ ;{ ;IC;"Returns the list of protected methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
;T;[o;=
;3I"
overload;F;40;;y;50;)I" protected_methods(all=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @;[ ;I"@return [Array];T;0; @;!F;6i ;>0;[[I"all;TI" true;T; @;[ ;I"Returns the list of protected methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
@overload protected_methods(all=true)
@return [Array];T;0; @;!F;"o;#;$T;%il;&ir;'@];(I"VALUE
rb_obj_protected_methods(int argc, const VALUE *argv, VALUE obj)
{
return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_prot_i);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#private_methods;F;[[@c0;[[@i;T;:private_methods;0;[ ;{ ;IC;"Returns the list of private methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
;T;[o;=
;3I"
overload;F;40;;z;50;)I"private_methods(all=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @2;[ ;I"@return [Array];T;0; @2;!F;6i ;>0;[[I"all;TI" true;T; @2;[ ;I"Returns the list of private methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
@overload private_methods(all=true)
@return [Array];T;0; @2;!F;"o;#;$T;%i{;&i;'@];(I"VALUE
rb_obj_private_methods(int argc, const VALUE *argv, VALUE obj)
{
return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_priv_i);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#public_methods;F;[[@c0;[[@i;T;:public_methods;0;[ ;{ ;IC;"Returns the list of public methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
;T;[o;=
;3I"
overload;F;40;;{;50;)I"public_methods(all=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @Q;[ ;I"@return [Array];T;0; @Q;!F;6i ;>0;[[I"all;TI" true;T; @Q;[ ;I"Returns the list of public methods accessible to obj. If
the all parameter is set to false
, only those methods
in the receiver will be listed.
@overload public_methods(all=true)
@return [Array];T;0; @Q;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_public_methods(int argc, const VALUE *argv, VALUE obj)
{
return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_pub_i);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#instance_variables;F;[ ;[[I"variable.c;Ti*;T;:instance_variables;0;[ ;{ ;IC;"Returns an array of instance variable names for the receiver. Note
that simply defining an accessor does not create the corresponding
instance variable.
class Fred
attr_accessor :a1
def initialize
@iv = 3
end
end
Fred.new.instance_variables #=> [:@iv]
;T;[o;=
;3I"
overload;F;40;;|;50;)I"instance_variables;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @p;[ ;I"@return [Array];T;0; @p;!F;6i ;>0;[ ; @p;[ ;I"NReturns an array of instance variable names for the receiver. Note
that simply defining an accessor does not create the corresponding
instance variable.
class Fred
attr_accessor :a1
def initialize
@iv = 3
end
end
Fred.new.instance_variables #=> [:@iv]
@overload instance_variables
@return [Array];T;0; @p;!F;"o;#;$T;%i;&i';'@];(I"VALUE
rb_obj_instance_variables(VALUE obj)
{
VALUE ary;
ary = rb_ary_new();
rb_ivar_foreach(obj, ivar_i, ary);
return ary;
};T;)I"
VALUE;T;*To;;F;
;;;;I"!Object#instance_variable_get;F;[[I"iv;T0;[[@i?;T;:instance_variable_get;0;[ ;{ ;IC;"Returns the value of the given instance variable, or nil if the
instance variable is not set. The @
part of the
variable name should be included for regular instance
variables. Throws a NameError exception if the
supplied symbol is not valid as an instance variable name.
String arguments are converted to symbols.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_get(:@a) #=> "cat"
fred.instance_variable_get("@b") #=> 99
;T;[o;=
;3I"
overload;F;40;;};50;)I""instance_variable_get(symbol);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol;T0; @o;=
;3I"
overload;F;40;;};50;)I""instance_variable_get(string);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string;T0; @;[ ;I"Returns the value of the given instance variable, or nil if the
instance variable is not set. The @
part of the
variable name should be included for regular instance
variables. Throws a NameError exception if the
supplied symbol is not valid as an instance variable name.
String arguments are converted to symbols.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_get(:@a) #=> "cat"
fred.instance_variable_get("@b") #=> 99
@overload instance_variable_get(symbol)
@return [Object]
@overload instance_variable_get(string)
@return [Object];T;0; @;!F;"o;#;$T;%i);&i=;'@];(I"static VALUE
rb_obj_ivar_get(VALUE obj, VALUE iv)
{
ID id = id_for_var(obj, iv, instance);
if (!id) {
return Qnil;
}
return rb_ivar_get(obj, id);
};T;)I"static VALUE;T;*To;;F;
;;;;I"!Object#instance_variable_set;F;[[I"iv;T0[I"val;T0;[[@ia;T;:instance_variable_set;0;[ ;{ ;IC;"zSets the instance variable named by symbol to the given
object, thereby frustrating the efforts of the class's
author to attempt to provide proper encapsulation. The variable
does not have to exist prior to this call.
If the instance variable name is passed as a string, that string
is converted to a symbol.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_set(:@a, 'dog') #=> "dog"
fred.instance_variable_set(:@c, 'cat') #=> "cat"
fred.inspect #=> "#"
;T;[o;=
;3I"
overload;F;40;;~;50;)I"'instance_variable_set(symbol, obj);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol;T0[I"obj;T0; @o;=
;3I"
overload;F;40;;~;50;)I"'instance_variable_set(string, obj);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string;T0[I"obj;T0; @;[ ;I"Sets the instance variable named by symbol to the given
object, thereby frustrating the efforts of the class's
author to attempt to provide proper encapsulation. The variable
does not have to exist prior to this call.
If the instance variable name is passed as a string, that string
is converted to a symbol.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_set(:@a, 'dog') #=> "dog"
fred.instance_variable_set(:@c, 'cat') #=> "cat"
fred.inspect #=> "#"
@overload instance_variable_set(symbol, obj)
@return [Object]
@overload instance_variable_set(string, obj)
@return [Object];T;0; @;!F;"o;#;$T;%iJ;&i_;'@];(I"static VALUE
rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
{
ID id = id_for_var(obj, iv, instance);
if (!id) id = rb_intern_str(iv);
return rb_ivar_set(obj, id, val);
};T;)I"static VALUE;T;*To;;F;
;;;;I"&Object#instance_variable_defined?;F;[[I"iv;T0;[[@i};T;:instance_variable_defined?;0;[ ;{ ;IC;"Returns true
if the given instance variable is
defined in obj.
String arguments are converted to symbols.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_defined?(:@a) #=> true
fred.instance_variable_defined?("@b") #=> true
fred.instance_variable_defined?("@c") #=> false;T;[o;=
;3I"
overload;F;40;;;50;)I"'instance_variable_defined?(symbol);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"symbol;T0; @o;=
;3I"
overload;F;40;;;50;)I"'instance_variable_defined?(string);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"string;T0; @;[ ;I"Returns true
if the given instance variable is
defined in obj.
String arguments are converted to symbols.
class Fred
def initialize(p1, p2)
@a, @b = p1, p2
end
end
fred = Fred.new('cat', 99)
fred.instance_variable_defined?(:@a) #=> true
fred.instance_variable_defined?("@b") #=> true
fred.instance_variable_defined?("@c") #=> false
@overload instance_variable_defined?(symbol)
@return [Boolean]
@overload instance_variable_defined?(string)
@return [Boolean];T;0; @;!F;"o;#;$T;%ii;&i{;6i ;'@];(I"static VALUE
rb_obj_ivar_defined(VALUE obj, VALUE iv)
{
ID id = id_for_var(obj, iv, instance);
if (!id) {
return Qfalse;
}
return rb_ivar_defined(obj, id);
};T;)I"static VALUE;T;*To;;F;
;;;;I"$Object#remove_instance_variable;F;[[I" name;T0;[[@uia;T;:remove_instance_variable;0;[ ;{ ;IC;"lRemoves the named instance variable from obj, returning that
variable's value.
String arguments are converted to symbols.
class Dummy
attr_reader :var
def initialize
@var = 99
end
def remove
remove_instance_variable(:@var)
end
end
d = Dummy.new
d.var #=> 99
d.remove #=> 99
d.var #=> nil
;T;[o;=
;3I"
overload;F;40;;{;50;)I"%remove_instance_variable(symbol);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol;T0; @o;=
;3I"
overload;F;40;;{;50;)I"%remove_instance_variable(string);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string;T0; @;[ ;I"Removes the named instance variable from obj, returning that
variable's value.
String arguments are converted to symbols.
class Dummy
attr_reader :var
def initialize
@var = 99
end
def remove
remove_instance_variable(:@var)
end
end
d = Dummy.new
d.var #=> 99
d.remove #=> 99
d.var #=> nil
@overload remove_instance_variable(symbol)
@return [Object]
@overload remove_instance_variable(string)
@return [Object];T;0; @;!F;"o;#;$T;%iI;&i_;'@];(I"TVALUE
rb_obj_remove_instance_variable(VALUE obj, VALUE name)
{
VALUE val = Qnil;
const ID id = id_for_var(obj, name, an, instance);
st_data_t n, v;
struct st_table *iv_index_tbl;
st_data_t index;
rb_check_frozen(obj);
if (!id) {
goto not_defined;
}
switch (BUILTIN_TYPE(obj)) {
case T_OBJECT:
iv_index_tbl = ROBJECT_IV_INDEX_TBL(obj);
if (!iv_index_tbl) break;
if (!st_lookup(iv_index_tbl, (st_data_t)id, &index)) break;
if (ROBJECT_NUMIV(obj) <= index) break;
val = ROBJECT_IVPTR(obj)[index];
if (val != Qundef) {
ROBJECT_IVPTR(obj)[index] = Qundef;
return val;
}
break;
case T_CLASS:
case T_MODULE:
n = id;
if (RCLASS_IV_TBL(obj) && st_delete(RCLASS_IV_TBL(obj), &n, &v)) {
return (VALUE)v;
}
break;
default:
if (FL_TEST(obj, FL_EXIVAR)) {
if (generic_ivar_remove(obj, id, &val)) {
return val;
}
}
break;
}
not_defined:
rb_name_err_raise("instance variable %1$s not defined",
obj, name);
UNREACHABLE_RETURN(Qnil);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#instance_of?;F;[[I"c;T0;[[@i1;T;:instance_of?;0;[ ;{ ;IC;"Returns true
if obj is an instance of the given
class. See also Object#kind_of?.
class A; end
class B < A; end
class C < B; end
b = B.new
b.instance_of? A #=> false
b.instance_of? B #=> true
b.instance_of? C #=> false;T;[o;=
;3I"
overload;F;40;;|;50;)I"instance_of?(class);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @J;[ ;I"@return [Boolean];T;0; @J;!F;6i ;>0;[ ; @J;[ ;I"CReturns true
if obj is an instance of the given
class. See also Object#kind_of?.
class A; end
class B < A; end
class C < B; end
b = B.new
b.instance_of? A #=> false
b.instance_of? B #=> true
b.instance_of? C #=> false
@overload instance_of?(class)
@return [Boolean];T;0; @J;!F;"o;#;$T;%i;&i(;6i ;'@];(I"VALUE
rb_obj_is_instance_of(VALUE obj, VALUE c)
{
c = class_or_module_required(c);
if (rb_obj_class(obj) == c) return Qtrue;
return Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#kind_of?;F;[[I"c;T0;[[@i];T;:
kind_of?;0;[ ;{ ;IC;"Returns true
if class is the class of
obj, or if class is one of the superclasses of
obj or modules included in obj.
module M; end
class A
include M
end
class B < A; end
class C < B; end
b = B.new
b.is_a? A #=> true
b.is_a? B #=> true
b.is_a? C #=> false
b.is_a? M #=> true
b.kind_of? A #=> true
b.kind_of? B #=> true
b.kind_of? C #=> false
b.kind_of? M #=> true;T;[o;=
;3I"
overload;F;40;:
is_a?;50;)I"is_a?(class);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @g;[ ;I"@return [Boolean];T;0; @g;!F;6i ;>0;[ ; @go;=
;3I"
overload;F;40;;};50;)I"kind_of?(class);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @g;[ ;I"@return [Boolean];T;0; @g;!F;6i ;>0;[ ; @g;[ ;I"gReturns true
if class is the class of
obj, or if class is one of the superclasses of
obj or modules included in obj.
module M; end
class A
include M
end
class B < A; end
class C < B; end
b = B.new
b.is_a? A #=> true
b.is_a? B #=> true
b.is_a? C #=> false
b.is_a? M #=> true
b.kind_of? A #=> true
b.kind_of? B #=> true
b.kind_of? C #=> false
b.kind_of? M #=> true
@overload is_a?(class)
@return [Boolean]
@overload kind_of?(class)
@return [Boolean];T;0; @g;!F;"o;#;$T;%i:;&iU;6i ;'@];(I"VALUE
rb_obj_is_kind_of(VALUE obj, VALUE c)
{
VALUE cl = CLASS_OF(obj);
c = class_or_module_required(c);
return class_search_ancestor(cl, RCLASS_ORIGIN(c)) ? Qtrue : Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#is_a?;F;[[I"c;T0;[[@i];T;;~;0;[ ;{ ;IC;"Returns true
if class is the class of
obj, or if class is one of the superclasses of
obj or modules included in obj.
module M; end
class A
include M
end
class B < A; end
class C < B; end
b = B.new
b.is_a? A #=> true
b.is_a? B #=> true
b.is_a? C #=> false
b.is_a? M #=> true
b.kind_of? A #=> true
b.kind_of? B #=> true
b.kind_of? C #=> false
b.kind_of? M #=> true;T;[o;=
;3I"
overload;F;40;;~;50;)I"is_a?(class);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @o;=
;3I"
overload;F;40;;};50;)I"kind_of?(class);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;@;0; @;!F;"o;#;$T;%i:;&iU;6i ;'@];(I"VALUE
rb_obj_is_kind_of(VALUE obj, VALUE c)
{
VALUE cl = CLASS_OF(obj);
c = class_or_module_required(c);
return class_search_ancestor(cl, RCLASS_ORIGIN(c)) ? Qtrue : Qfalse;
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#tap;F;[ ;[[@i;T;:tap;0;[ ;{ ;IC;"Yields self to the block, and then returns self.
The primary purpose of this method is to "tap into" a method chain,
in order to perform operations on intermediate results within the chain.
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
;T;[o;=
;3I"
overload;F;40;;;50;)I"tap;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"x;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I" @yield [x]
@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Yields self to the block, and then returns self.
The primary purpose of this method is to "tap into" a method chain,
in order to perform operations on intermediate results within the chain.
(1..10) .tap {|x| puts "original: #{x}" }
.to_a .tap {|x| puts "array: #{x}" }
.select {|x| x.even? } .tap {|x| puts "evens: #{x}" }
.map {|x| x*x } .tap {|x| puts "squares: #{x}" }
@overload tap
@yield [x]
@return [Object];T;0; @;!F;"o;#;$T;%iz;&i;'@];(I"GVALUE
rb_obj_tap(VALUE obj)
{
rb_yield(obj);
return obj;
};T;)I"
VALUE;T;*To:&YARD::CodeObjects::ConstantObject;[[I"numeric.c;Ti9;F;:Fixnum;:c;;;[ ;{ ;IC;"#An obsolete class, use Integer
;T;[ ;[ ;I"#An obsolete class, use Integer;T;0; @;!F;"o;#;$T;%i8;&i8;'@];I"Object::Fixnum;F:@valueI"rb_cInteger;To;;F;
;;;;I"Object#method;F;[[I"vid;T0;[[I"proc.c;TiD;T;:method;0;[ ;{ ;IC;"Looks up the named method as a receiver in obj, returning a
Method object (or raising NameError). The Method object acts as a
closure in obj's object instance, so instance variables and
the value of self
remain available.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
m = k.method(:hello)
m.call #=> "Hello, @iv = 99"
l = Demo.new('Fred')
m = l.method("hello")
m.call #=> "Hello, @iv = Fred"
Note that Method implements to_proc
method, which
means it can be used with iterators.
[ 1, 2, 3 ].each(&method(:puts)) # => prints 3 lines to stdout
out = File.open('test.txt', 'w')
[ 1, 2, 3 ].each(&out.method(:puts)) # => prints 3 lines to file
require 'date'
%w[2017-03-01 2017-03-02].collect(&Date.method(:parse))
#=> [#, #]
;T;[o;=
;3I"
overload;F;40;;;50;)I"method(sym);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"sym;T0; @;[ ;I"Looks up the named method as a receiver in obj, returning a
Method object (or raising NameError). The Method object acts as a
closure in obj's object instance, so instance variables and
the value of self
remain available.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
m = k.method(:hello)
m.call #=> "Hello, @iv = 99"
l = Demo.new('Fred')
m = l.method("hello")
m.call #=> "Hello, @iv = Fred"
Note that Method implements to_proc
method, which
means it can be used with iterators.
[ 1, 2, 3 ].each(&method(:puts)) # => prints 3 lines to stdout
out = File.open('test.txt', 'w')
[ 1, 2, 3 ].each(&out.method(:puts)) # => prints 3 lines to file
require 'date'
%w[2017-03-01 2017-03-02].collect(&Date.method(:parse))
#=> [#, #]
@overload method(sym);T;0; @;!F;"o;#;$T;%i;&i@;'@];(I"ZVALUE
rb_obj_method(VALUE obj, VALUE vid)
{
return obj_method(obj, vid, FALSE);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#public_method;F;[[I"vid;T0;[[@iQ;T;:public_method;0;[ ;{ ;IC;"6Similar to _method_, searches public method only.
;T;[o;=
;3I"
overload;F;40;;;50;)I"public_method(sym);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"sym;T0; @;[ ;I"USimilar to _method_, searches public method only.
@overload public_method(sym);T;0; @;!F;"o;#;$T;%iJ;&iM;'@];(I"`VALUE
rb_obj_public_method(VALUE obj, VALUE vid)
{
return obj_method(obj, vid, TRUE);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#singleton_method;F;[[I"vid;T0;[[@io;T;:singleton_method;0;[ ;{ ;IC;"^Similar to _method_, searches singleton method only.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi)
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) #=> NameError
;T;[o;=
;3I"
overload;F;40;;;50;)I"singleton_method(sym);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"sym;T0; @;[ ;I"Similar to _method_, searches singleton method only.
class Demo
def initialize(n)
@iv = n
end
def hello()
"Hello, @iv = #{@iv}"
end
end
k = Demo.new(99)
def k.hi
"Hi, @iv = #{@iv}"
end
m = k.singleton_method(:hi)
m.call #=> "Hi, @iv = 99"
m = k.singleton_method(:hello) #=> NameError
@overload singleton_method(sym);T;0; @;!F;"o;#;$T;%iW;&ik;'@];(I"VALUE
rb_obj_singleton_method(VALUE obj, VALUE vid)
{
const rb_method_entry_t *me;
VALUE klass = rb_singleton_class_get(obj);
ID id = rb_check_id(&vid);
if (NIL_P(klass) || NIL_P(klass = RCLASS_ORIGIN(klass))) {
undef:
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
obj, vid);
}
if (!id) {
VALUE m = mnew_missing_by_name(klass, obj, &vid, FALSE, rb_cMethod);
if (m) return m;
goto undef;
}
me = rb_method_entry_at(klass, id);
if (UNDEFINED_METHOD_ENTRY_P(me) ||
UNDEFINED_REFINED_METHOD_P(me->def)) {
vid = ID2SYM(id);
goto undef;
}
return mnew_from_me(me, klass, klass, obj, id, rb_cMethod, FALSE);
};T;)I"
VALUE;T;*To;;F;
;;;;I"#Object#define_singleton_method;F;[[@c0;[[@ig;T;:define_singleton_method;0;[ ;{ ;IC;"Defines a singleton method in the receiver. The _method_
parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
If a block is specified, it is used as the method body.
If a block or a method has parameters, they're used as method parameters.
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
chris = "Chris"
chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
chris.greet("Hi") #=> "Hi, I'm Chris!"
;T;[o;=
;3I"
overload;F;40;;;50;)I",define_singleton_method(symbol, method);T;IC;" ;T;[ ;[ ;I" ;T;0; @6;!F;6i ;>0;[[I"symbol;T0[I"method;T0; @6o;=
;3I"
overload;F;40;;;50;)I"$define_singleton_method(symbol);T;IC;" ;T;[o;2
;3I"
yield;F;4I"[];T;0;50; @6;[ ;I"@yield [];T;0; @6;!F;6i ;>0;[[I"symbol;T0; @6;[ ;I">Defines a singleton method in the receiver. The _method_
parameter can be a +Proc+, a +Method+ or an +UnboundMethod+ object.
If a block is specified, it is used as the method body.
If a block or a method has parameters, they're used as method parameters.
class A
class << self
def class_name
to_s
end
end
end
A.define_singleton_method(:who_am_i) do
"I am: #{class_name}"
end
A.who_am_i # ==> "I am: A"
guy = "Bob"
guy.define_singleton_method(:hello) { "#{self}: Hello there!" }
guy.hello #=> "Bob: Hello there!"
chris = "Chris"
chris.define_singleton_method(:greet) {|greeting| "#{greeting}, I'm Chris!" }
chris.greet("Hi") #=> "Hi, I'm Chris!"
@overload define_singleton_method(symbol, method)
@overload define_singleton_method(symbol)
@yield [];T;0; @6;!F;"o;#;$T;%iH;&id;'@];(I"static VALUE
rb_obj_define_method(int argc, VALUE *argv, VALUE obj)
{
VALUE klass = rb_singleton_class(obj);
return rb_mod_define_method(argc, argv, klass);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#send;F;[[@c0;[[I"vm_eval.c;Ti;T;: send;0;[ ;{ ;IC;"Invokes the method identified by _symbol_, passing it any
arguments specified. You can use __send__
if the name
+send+ clashes with an existing method in _obj_.
When the method is identified by a string, the string is converted
to a symbol.
BasicObject implements +__send__+, Kernel implements +send+.
class Klass
def hello(*args)
"Hello " + args.join(' ')
end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
;T;[ o;=
;3I"
overload;F;40;;;50;)I"send(symbol [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @^;[ ;I"@return [Object];T;0; @^;!F;6i ;>0;[[I"symbol[, args...];T0; @^o;=
;3I"
overload;F;40;:
__send__;50;)I"!__send__(symbol [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @^;[ ;I"@return [Object];T;0; @^;!F;6i ;>0;[[I"symbol[, args...];T0; @^o;=
;3I"
overload;F;40;;;50;)I"send(string [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @^;[ ;I"@return [Object];T;0; @^;!F;6i ;>0;[[I"string[, args...];T0; @^o;=
;3I"
overload;F;40;;;50;)I"!__send__(string [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @^;[ ;I"@return [Object];T;0; @^;!F;6i ;>0;[[I"string[, args...];T0; @^;[ ;I" Invokes the method identified by _symbol_, passing it any
arguments specified. You can use __send__
if the name
+send+ clashes with an existing method in _obj_.
When the method is identified by a string, the string is converted
to a symbol.
BasicObject implements +__send__+, Kernel implements +send+.
class Klass
def hello(*args)
"Hello " + args.join(' ')
end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
@overload send(symbol [, args...])
@return [Object]
@overload __send__(symbol [, args...])
@return [Object]
@overload send(string [, args...])
@return [Object]
@overload __send__(string [, args...])
@return [Object];T;0; @^;!F;"o;#;$T;%i;&i;'@];(I"vVALUE
rb_f_send(int argc, VALUE *argv, VALUE recv)
{
return send_internal_kw(argc, argv, recv, CALL_FCALL);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Object#public_send;F;[[@c0;[[@di;T;:public_send;0;[ ;{ ;IC;"Invokes the method identified by _symbol_, passing it any
arguments specified. Unlike send, public_send calls public
methods only.
When the method is identified by a string, the string is converted
to a symbol.
1.public_send(:puts, "hello") # causes NoMethodError
;T;[o;=
;3I"
overload;F;40;;;50;)I"$public_send(symbol [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol[, args...];T0; @o;=
;3I"
overload;F;40;;;50;)I"$public_send(string [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string[, args...];T0; @;[ ;I"Invokes the method identified by _symbol_, passing it any
arguments specified. Unlike send, public_send calls public
methods only.
When the method is identified by a string, the string is converted
to a symbol.
1.public_send(:puts, "hello") # causes NoMethodError
@overload public_send(symbol [, args...])
@return [Object]
@overload public_send(string [, args...])
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@];(I"static VALUE
rb_f_public_send(int argc, VALUE *argv, VALUE recv)
{
return send_internal_kw(argc, argv, recv, CALL_PUBLIC);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Object#rb_fatal;F;[[I"msg;T0;[[I" ext/-test-/fatal/rb_fatal.c;Ti;T;:
rb_fatal;0;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @;'@];(I"static VALUE
ruby_fatal(VALUE obj, VALUE msg)
{
const char *cmsg = NULL;
(void)obj;
cmsg = RSTRING_PTR(msg);
rb_fatal("%s", cmsg);
return 0; /* never reached */
};T;)I"static VALUE;T;*To;;[[I"7ext/-test-/wait_for_single_fd/wait_for_single_fd.c;Ti[;F;:RB_WAITFD_IN;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @;'@];I"Object::RB_WAITFD_IN;F;I"INT2NUM(RB_WAITFD_IN);To;;[[@i\;F;:RB_WAITFD_OUT;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @;'@];I"Object::RB_WAITFD_OUT;F;I"INT2NUM(RB_WAITFD_OUT);To;;[[@i];F;:RB_WAITFD_PRI;;;;;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @;'@];I"Object::RB_WAITFD_PRI;F;I"INT2NUM(RB_WAITFD_PRI);To;;F;
;;;;I"Object#object_id;F;[ ;[[I" gc.c;Ti;T;:object_id;0;[ ;{ ;IC;"4call-seq:
obj.__id__ -> integer
obj.object_id -> integer
Returns an integer identifier for +obj+.
The same number will be returned on all calls to +object_id+ for a given
object, and no two active objects will share an id.
Note: that some objects of builtin classes are reused for optimization.
This is the case for immediate values and frozen string literals.
BasicObject implements +__id__+, Kernel implements +object_id+.
Immediate values are not passed by reference but are passed by value:
+nil+, +true+, +false+, Fixnums, Symbols, and some Floats.
Object.new.object_id == Object.new.object_id # => false
(21 * 2).object_id == (21 * 2).object_id # => true
"hello".object_id == "hello".object_id # => false
"hi".freeze.object_id == "hi".freeze.object_id # => true
;T;[ ;[ ;I"6
call-seq:
obj.__id__ -> integer
obj.object_id -> integer
Returns an integer identifier for +obj+.
The same number will be returned on all calls to +object_id+ for a given
object, and no two active objects will share an id.
Note: that some objects of builtin classes are reused for optimization.
This is the case for immediate values and frozen string literals.
BasicObject implements +__id__+, Kernel implements +object_id+.
Immediate values are not passed by reference but are passed by value:
+nil+, +true+, +false+, Fixnums, Symbols, and some Floats.
Object.new.object_id == Object.new.object_id # => false
(21 * 2).object_id == (21 * 2).object_id # => true
"hello".object_id == "hello".object_id # => false
"hi".freeze.object_id == "hi".freeze.object_id # => true
;T;0; @ ;!F;"o;#;$T;%i;&i;'@];(I"VALUE
rb_obj_id(VALUE obj)
{
/*
* 32-bit VALUE space
* MSB ------------------------ LSB
* false 00000000000000000000000000000000
* true 00000000000000000000000000000010
* nil 00000000000000000000000000000100
* undef 00000000000000000000000000000110
* symbol ssssssssssssssssssssssss00001110
* object oooooooooooooooooooooooooooooo00 = 0 (mod sizeof(RVALUE))
* fixnum fffffffffffffffffffffffffffffff1
*
* object_id space
* LSB
* false 00000000000000000000000000000000
* true 00000000000000000000000000000010
* nil 00000000000000000000000000000100
* undef 00000000000000000000000000000110
* symbol 000SSSSSSSSSSSSSSSSSSSSSSSSSSS0 S...S % A = 4 (S...S = s...s * A + 4)
* object oooooooooooooooooooooooooooooo0 o...o % A = 0
* fixnum fffffffffffffffffffffffffffffff1 bignum if required
*
* where A = sizeof(RVALUE)/4
*
* sizeof(RVALUE) is
* 20 if 32-bit, double is 4-byte aligned
* 24 if 32-bit, double is 8-byte aligned
* 40 if 64-bit
*/
return rb_find_object_id(obj, cached_object_id);
};T;)I"
VALUE;T;*To;;[[I"
bignum.c;Ti;F;:Bignum;;;;;[ ;{ ;IC;"#An obsolete class, use Integer
;T;[ ;[ ;I"#An obsolete class, use Integer;T;0; @ ;!F;"o;#;$T;%i;&i;'o;L;M0;N0;O0;;T;'@;Q@];R0;I"Object::Bignum;T;I"rb_cInteger;T;A@];BIC;[ ;A@];CIC;[o; ;IC;[Eo;;F;
;;;;I"Kernel#Pathname;F;[[I"str;T0;[[I"ext/pathname/pathname.c;Ti#;T;:
Pathname;0;[ ;{ ;IC;"Y:call-seq:
Pathname(path) -> pathname
Creates a new Pathname object from the given string, +path+, and returns
pathname object.
In order to use this constructor, you must first require the Pathname
standard library extension.
require 'pathname'
Pathname("/home/zzak")
#=> #
See also Pathname::new for more information.
;T;[ ;[ ;I"Z:call-seq:
Pathname(path) -> pathname
Creates a new Pathname object from the given string, +path+, and returns
pathname object.
In order to use this constructor, you must first require the Pathname
standard library extension.
require 'pathname'
Pathname("/home/zzak")
#=> #
See also Pathname::new for more information.
;T;0; @& ;!F;"o;#;$T;%i;&i!;'@$ ;(I"static VALUE
path_f_pathname(VALUE self, VALUE str)
{
if (CLASS_OF(str) == rb_cPathname)
return str;
return rb_class_new_instance(1, &str, rb_cPathname);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#load;F;[[@c0;[[I"load.c;Ti;T;: load;0;[ ;{ ;IC;"Loads and executes the Ruby
program in the file _filename_. If the filename does not
resolve to an absolute path, the file is searched for in the library
directories listed in $:
. If the optional _wrap_
parameter is +true+, the loaded script will be executed
under an anonymous module, protecting the calling program's global
namespace. In no circumstance will any local variables in the loaded
file be propagated to the loading environment.
;T;[o;=
;3I"
overload;F;40;;;50;)I"load(filename, wrap=false);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I" true;T; @7 ;[ ;I"@return [true];T;0; @7 ;!F;6i ;>0;[[I"
filename;T0[I" wrap;TI"
false;T; @7 ;[ ;I"Loads and executes the Ruby
program in the file _filename_. If the filename does not
resolve to an absolute path, the file is searched for in the library
directories listed in $:
. If the optional _wrap_
parameter is +true+, the loaded script will be executed
under an anonymous module, protecting the calling program's global
namespace. In no circumstance will any local variables in the loaded
file be propagated to the loading environment.
@overload load(filename, wrap=false)
@return [true];T;0; @7 ;!F;"o;#;$T;%i;&i;'@$ ;(I"?static VALUE
rb_f_load(int argc, VALUE *argv, VALUE _)
{
VALUE fname, wrap, path, orig_fname;
rb_scan_args(argc, argv, "11", &fname, &wrap);
orig_fname = rb_get_path_check_to_string(fname);
fname = rb_str_encode_ospath(orig_fname);
RUBY_DTRACE_HOOK(LOAD_ENTRY, RSTRING_PTR(orig_fname));
path = rb_find_file(fname);
if (!path) {
if (!rb_file_load_ok(RSTRING_PTR(fname)))
load_failed(orig_fname);
path = fname;
}
rb_load_internal(path, RTEST(wrap));
RUBY_DTRACE_HOOK(LOAD_RETURN, RSTRING_PTR(orig_fname));
return Qtrue;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#require;F;[[I"
fname;T0;[[@= iT;T;:require;0;[ ;{ ;IC;"ELoads the given +name+, returning +true+ if successful and +false+ if the
feature is already loaded.
If the filename does not resolve to an absolute path, it will be searched
for in the directories listed in $LOAD_PATH
($:
).
If the filename has the extension ".rb", it is loaded as a source file; if
the extension is ".so", ".o", or ".dll", or the default shared library
extension on the current platform, Ruby loads the shared library as a
Ruby extension. Otherwise, Ruby tries adding ".rb", ".so", and so on
to the name until found. If the file named cannot be found, a LoadError
will be raised.
For Ruby extensions the filename given may use any shared library
extension. For example, on Linux the socket extension is "socket.so" and
require 'socket.dll'
will load the socket extension.
The absolute path of the loaded file is added to
$LOADED_FEATURES
($"
). A file will not be
loaded again if its path already appears in $"
. For example,
require 'a'; require './a'
will not load a.rb
again.
require "my-library.rb"
require "db-driver"
Any constants or globals within the loaded source file will be available
in the calling program's global namespace. However, local variables will
not be propagated to the loading environment.
;T;[o;=
;3I"
overload;F;40;;;50;)I"require(name);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @Y ;[ ;I"@return [Boolean];T;0; @Y ;!F;6i ;>0;[[I" name;T0; @Y ;[ ;I"tLoads the given +name+, returning +true+ if successful and +false+ if the
feature is already loaded.
If the filename does not resolve to an absolute path, it will be searched
for in the directories listed in $LOAD_PATH
($:
).
If the filename has the extension ".rb", it is loaded as a source file; if
the extension is ".so", ".o", or ".dll", or the default shared library
extension on the current platform, Ruby loads the shared library as a
Ruby extension. Otherwise, Ruby tries adding ".rb", ".so", and so on
to the name until found. If the file named cannot be found, a LoadError
will be raised.
For Ruby extensions the filename given may use any shared library
extension. For example, on Linux the socket extension is "socket.so" and
require 'socket.dll'
will load the socket extension.
The absolute path of the loaded file is added to
$LOADED_FEATURES
($"
). A file will not be
loaded again if its path already appears in $"
. For example,
require 'a'; require './a'
will not load a.rb
again.
require "my-library.rb"
require "db-driver"
Any constants or globals within the loaded source file will be available
in the calling program's global namespace. However, local variables will
not be propagated to the loading environment.
@overload require(name)
@return [Boolean];T;0; @Y ;!F;"o;#;$T;%i0;&iQ;'@$ ;(I"XVALUE
rb_f_require(VALUE obj, VALUE fname)
{
return rb_require_string(fname);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Kernel#require_relative;F;[[I"
fname;T0;[[@= ib;T;:require_relative;0;[ ;{ ;IC;"Ruby tries to load the library named _string_ relative to the requiring
file's path. If the file's path cannot be determined a LoadError is raised.
If a file is loaded +true+ is returned and false otherwise.
;T;[o;=
;3I"
overload;F;40;;;50;)I"require_relative(string);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @x ;[ ;I"@return [Boolean];T;0; @x ;!F;6i ;>0;[[I"string;T0; @x ;[ ;I" Ruby tries to load the library named _string_ relative to the requiring
file's path. If the file's path cannot be determined a LoadError is raised.
If a file is loaded +true+ is returned and false otherwise.
@overload require_relative(string)
@return [Boolean];T;0; @x ;!F;"o;#;$T;%iZ;&i`;'@$ ;(I"VALUE
rb_f_require_relative(VALUE obj, VALUE fname)
{
VALUE base = rb_current_realfilepath();
if (NIL_P(base)) {
rb_loaderror("cannot infer basepath");
}
base = rb_file_dirname(base);
return rb_require_string(rb_file_absolute_path(fname, base));
};T;)I"
VALUE;T;*To;;F;
;;;;I"Kernel#autoload;F;[[I"sym;T0[I" file;T0;[[@= i;T;:
autoload;0;[ ;{ ;IC;"Registers _filename_ to be loaded (using Kernel::require)
the first time that _module_ (which may be a String or
a symbol) is accessed.
autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
;T;[o;=
;3I"
overload;F;40;;;50;)I"autoload(module, filename);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @ ;[ ;I"@return [nil];T;0; @ ;!F;6i ;>0;[ ; @ ;[ ;I"Registers _filename_ to be loaded (using Kernel::require)
the first time that _module_ (which may be a String or
a symbol) is accessed.
autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
@overload autoload(module, filename)
@return [nil];T;0; @ ;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
{
VALUE klass = rb_class_real(rb_vm_cbase());
if (NIL_P(klass)) {
rb_raise(rb_eTypeError, "Can not set autoload on singleton class");
}
return rb_mod_autoload(klass, sym, file);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#autoload?;F;[[@c0;[[@= i;T;:autoload?;0;[ ;{ ;IC;"Returns _filename_ to be loaded if _name_ is registered as
+autoload+.
autoload(:B, "b")
autoload?(:B) #=> "b";T;[o;=
;3I"
overload;F;40;;;50;)I""autoload?(name, inherit=true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;TI"nil;T; @ ;[ ;I"@return [String, nil];T;0; @ ;!F;6i ;>0;[[I" name;T0[I"inherit;TI" true;T; @ ;[ ;I"Returns _filename_ to be loaded if _name_ is registered as
+autoload+.
autoload(:B, "b")
autoload?(:B) #=> "b"
@overload autoload?(name, inherit=true)
@return [String, nil];T;0; @ ;!F;"o;#;$T;%i;&i;6i ;'@$ ;(I"static VALUE
rb_f_autoload_p(int argc, VALUE *argv, VALUE obj)
{
/* use rb_vm_cbase() as same as rb_f_autoload. */
VALUE klass = rb_vm_cbase();
if (NIL_P(klass)) {
return Qnil;
}
return rb_mod_autoload_p(argc, argv, klass);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#set_trace_func;F;[[I"
trace;T0;[[I"vm_trace.c;Ti ;T;:set_trace_func;0;[ ;{ ;IC;"+Establishes _proc_ as the handler for tracing, or disables
tracing if the parameter is +nil+.
*Note:* this method is obsolete, please use TracePoint instead.
_proc_ takes up to six parameters:
* an event name
* a filename
* a line number
* an object id
* a binding
* the name of a class
_proc_ is invoked whenever an event occurs.
Events are:
+c-call+:: call a C-language routine
+c-return+:: return from a C-language routine
+call+:: call a Ruby method
+class+:: start a class or module definition
+end+:: finish a class or module definition
+line+:: execute code on a new line
+raise+:: raise an exception
+return+:: return from a Ruby method
Tracing is disabled within the context of _proc_.
class Test
def test
a = 1
b = 2
end
end
set_trace_func proc { |event, file, line, id, binding, classname|
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
t = Test.new
t.test
line prog.rb:11 false
c-call prog.rb:11 new Class
c-call prog.rb:11 initialize Object
c-return prog.rb:11 initialize Object
c-return prog.rb:11 new Class
line prog.rb:12 false
call prog.rb:2 test Test
line prog.rb:3 test Test
line prog.rb:4 test Test
return prog.rb:4 test Test
;T;[o;=
;3I"
overload;F;40;;;50;)I"set_trace_func(proc);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I" Proc;T; @ ;[ ;I"@return [Proc];T;0; @ ;!F;6i ;>0;[[I" proc;T0; @ o;=
;3I"
overload;F;40;;;50;)I"set_trace_func(nil);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @ ;[ ;I"@return [nil];T;0; @ ;!F;6i ;>0;[[I"nil;T0; @ ;[ ;I"Establishes _proc_ as the handler for tracing, or disables
tracing if the parameter is +nil+.
*Note:* this method is obsolete, please use TracePoint instead.
_proc_ takes up to six parameters:
* an event name
* a filename
* a line number
* an object id
* a binding
* the name of a class
_proc_ is invoked whenever an event occurs.
Events are:
+c-call+:: call a C-language routine
+c-return+:: return from a C-language routine
+call+:: call a Ruby method
+class+:: start a class or module definition
+end+:: finish a class or module definition
+line+:: execute code on a new line
+raise+:: raise an exception
+return+:: return from a Ruby method
Tracing is disabled within the context of _proc_.
class Test
def test
a = 1
b = 2
end
end
set_trace_func proc { |event, file, line, id, binding, classname|
printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
}
t = Test.new
t.test
line prog.rb:11 false
c-call prog.rb:11 new Class
c-call prog.rb:11 initialize Object
c-return prog.rb:11 initialize Object
c-return prog.rb:11 new Class
line prog.rb:12 false
call prog.rb:2 test Test
line prog.rb:3 test Test
line prog.rb:4 test Test
return prog.rb:4 test Test
@overload set_trace_func(proc)
@return [Proc]
@overload set_trace_func(nil)
@return [nil];T;0; @ ;!F;"o;#;$T;%i;&i;'@$ ;(I"Cstatic VALUE
set_trace_func(VALUE obj, VALUE trace)
{
rb_remove_event_hook(call_trace_func);
if (NIL_P(trace)) {
return Qnil;
}
if (!rb_obj_is_proc(trace)) {
rb_raise(rb_eTypeError, "trace_func needs to be Proc");
}
rb_add_event_hook(call_trace_func, RUBY_EVENT_ALL, trace);
return trace;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#raise;F;[[I"*v;T0[I"_;T0;[[@fi ;T;:
raise;0;[ ;{ ;IC;"With no arguments, raises the exception in $!
or raises
a RuntimeError if $!
is +nil+. With a single +String+
argument, raises a +RuntimeError+ with the string as a message. Otherwise,
the first parameter should be an +Exception+ class (or another
object that returns an +Exception+ object when sent an +exception+
message). The optional second parameter sets the message associated with
the exception (accessible via Exception#message), and the third parameter
is an array of callback information (accessible via Exception#backtrace).
The +cause+ of the generated exception (accessible via Exception#cause)
is automatically set to the "current" exception ($!
), if any.
An alternative value, either an +Exception+ object or +nil+, can be
specified via the +:cause+ argument.
Exceptions are caught by the +rescue+ clause of
begin...end
blocks.
raise "Failed to create socket"
raise ArgumentError, "No parameters", caller
;T;[o;=
;3I"
overload;F;40;;;50;)I"
raise;T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[ ; @
o;=
;3I"
overload;F;40;;;50;)I"raise(string, cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[[I"string;T0[I"cause:;TI"$!;T; @
o;=
;3I"
overload;F;40;;;50;)I"5raise(exception [, string [, array]], cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[[I""exception[, string [, array]];T0[I"cause:;TI"$!;T; @
o;=
;3I"
overload;F;40;: fail;50;)I" fail;T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[ ; @
o;=
;3I"
overload;F;40;;;50;)I"fail(string, cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[[I"string;T0[I"cause:;TI"$!;T; @
o;=
;3I"
overload;F;40;;;50;)I"4fail(exception [, string [, array]], cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[[I""exception[, string [, array]];T0[I"cause:;TI"$!;T; @
;[ ;I"With no arguments, raises the exception in $!
or raises
a RuntimeError if $!
is +nil+. With a single +String+
argument, raises a +RuntimeError+ with the string as a message. Otherwise,
the first parameter should be an +Exception+ class (or another
object that returns an +Exception+ object when sent an +exception+
message). The optional second parameter sets the message associated with
the exception (accessible via Exception#message), and the third parameter
is an array of callback information (accessible via Exception#backtrace).
The +cause+ of the generated exception (accessible via Exception#cause)
is automatically set to the "current" exception ($!
), if any.
An alternative value, either an +Exception+ object or +nil+, can be
specified via the +:cause+ argument.
Exceptions are caught by the +rescue+ clause of
begin...end
blocks.
raise "Failed to create socket"
raise ArgumentError, "No parameters", caller
@overload raise
@overload raise(string, cause: $!)
@overload raise(exception [, string [, array]], cause: $!)
@overload fail
@overload fail(string, cause: $!)
@overload fail(exception [, string [, array]], cause: $!);T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"Tstatic VALUE
f_raise(int c, VALUE *v, VALUE _)
{
return rb_f_raise(c, v);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#fail;F;[[I"*v;T0[I"_;T0;[[@fi ;T;;;0;[ ;{ ;IC;"With no arguments, raises the exception in $!
or raises
a RuntimeError if $!
is +nil+. With a single +String+
argument, raises a +RuntimeError+ with the string as a message. Otherwise,
the first parameter should be an +Exception+ class (or another
object that returns an +Exception+ object when sent an +exception+
message). The optional second parameter sets the message associated with
the exception (accessible via Exception#message), and the third parameter
is an array of callback information (accessible via Exception#backtrace).
The +cause+ of the generated exception (accessible via Exception#cause)
is automatically set to the "current" exception ($!
), if any.
An alternative value, either an +Exception+ object or +nil+, can be
specified via the +:cause+ argument.
Exceptions are caught by the +rescue+ clause of
begin...end
blocks.
raise "Failed to create socket"
raise ArgumentError, "No parameters", caller
;T;[o;=
;3I"
overload;F;40;;;50;)I"
raise;T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[ ; @]
o;=
;3I"
overload;F;40;;;50;)I"raise(string, cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[[I"string;T0[I"cause:;TI"$!;T; @]
o;=
;3I"
overload;F;40;;;50;)I"5raise(exception [, string [, array]], cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[[I""exception[, string [, array]];T0[I"cause:;TI"$!;T; @]
o;=
;3I"
overload;F;40;;;50;)I" fail;T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[ ; @]
o;=
;3I"
overload;F;40;;;50;)I"fail(string, cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[[I"string;T0[I"cause:;TI"$!;T; @]
o;=
;3I"
overload;F;40;;;50;)I"4fail(exception [, string [, array]], cause: $!);T;IC;" ;T;[ ;[ ;I" ;T;0; @]
;!F;6i ;>0;[[I""exception[, string [, array]];T0[I"cause:;TI"$!;T; @]
;[ ;@Y
;0; @]
;!F;"o;#;$T;%i;&i;'@$ ;(I"Tstatic VALUE
f_raise(int c, VALUE *v, VALUE _)
{
return rb_f_raise(c, v);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#global_variables;F;[ ;[[@fi;T;:global_variables;0;[ ;{ ;IC;"{Returns an array of the names of global variables.
global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
;T;[o;=
;3I"
overload;F;40;;;50;)I"global_variables;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @
;[ ;I"@return [Array];T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"Returns an array of the names of global variables.
global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
@overload global_variables
@return [Array];T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"Ustatic VALUE
f_global_variables(VALUE _)
{
return rb_f_global_variables();
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#__method__;F;[ ;[[@fi;T;:__method__;0;[ ;{ ;IC;"Returns the name at the definition of the current method as a
Symbol.
If called outside of a method, it returns nil
.
;T;[o;=
;3I"
overload;F;40;;;50;)I"__method__;T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"Returns the name at the definition of the current method as a
Symbol.
If called outside of a method, it returns nil
.
@overload __method__;T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_method_name(VALUE _)
{
ID fname = prev_frame_func(); /* need *method* ID */
if (fname) {
return ID2SYM(fname);
}
else {
return Qnil;
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#__callee__;F;[ ;[[@fi;T;:__callee__;0;[ ;{ ;IC;"{Returns the called name of the current method as a Symbol.
If called outside of a method, it returns nil
.
;T;[o;=
;3I"
overload;F;40;;;50;)I"__callee__;T;IC;" ;T;[ ;[ ;I" ;T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"Returns the called name of the current method as a Symbol.
If called outside of a method, it returns nil
.
@overload __callee__;T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_callee_name(VALUE _)
{
ID fname = prev_frame_callee(); /* need *callee* ID */
if (fname) {
return ID2SYM(fname);
}
else {
return Qnil;
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#__dir__;F;[ ;[[@fi;T;:__dir__;0;[ ;{ ;IC;"+Returns the canonicalized absolute path of the directory of the file from
which this method is called. It means symlinks in the path is resolved.
If __FILE__
is nil
, it returns nil
.
The return value equals to File.dirname(File.realpath(__FILE__))
.
;T;[o;=
;3I"
overload;F;40;;;50;)I"__dir__;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @
;[ ;I"@return [String];T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"SReturns the canonicalized absolute path of the directory of the file from
which this method is called. It means symlinks in the path is resolved.
If __FILE__
is nil
, it returns nil
.
The return value equals to File.dirname(File.realpath(__FILE__))
.
@overload __dir__
@return [String];T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
f_current_dirname(VALUE _)
{
VALUE base = rb_current_realfilepath();
if (NIL_P(base)) {
return Qnil;
}
base = rb_file_dirname(base);
return base;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#trace_var;F;[[I"*a;T0[I"_;T0;[[@fi;T;:trace_var;0;[ ;{ ;IC;"Controls tracing of assignments to global variables. The parameter
+symbol+ identifies the variable (as either a string name or a
symbol identifier). _cmd_ (which may be a string or a
+Proc+ object) or block is executed whenever the variable
is assigned. The block or +Proc+ object receives the
variable's new value as a parameter. Also see
Kernel::untrace_var.
trace_var :$_, proc {|v| puts "$_ is now '#{v}'" }
$_ = "hello"
$_ = ' there'
produces:
$_ is now 'hello'
$_ is now ' there'
;T;[o;=
;3I"
overload;F;40;;;50;)I"trace_var(symbol, cmd );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"symbol;T0[I"cmd;T0; @o;=
;3I"
overload;F;40;;;50;)I"trace_var(symbol);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"val;T; @o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@yield [val]
@return [nil];T;0; @;!F;6i ;>0;[[I"symbol;T0; @;[ ;I"pControls tracing of assignments to global variables. The parameter
+symbol+ identifies the variable (as either a string name or a
symbol identifier). _cmd_ (which may be a string or a
+Proc+ object) or block is executed whenever the variable
is assigned. The block or +Proc+ object receives the
variable's new value as a parameter. Also see
Kernel::untrace_var.
trace_var :$_, proc {|v| puts "$_ is now '#{v}'" }
$_ = "hello"
$_ = ' there'
produces:
$_ is now 'hello'
$_ is now ' there'
@overload trace_var(symbol, cmd )
@return [nil]
@overload trace_var(symbol)
@yield [val]
@return [nil];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"bstatic VALUE
f_trace_var(int c, const VALUE *a, VALUE _)
{
return rb_f_trace_var(c, a);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#untrace_var;F;[[I"*a;T0[I"_;T0;[[@fi;T;:untrace_var;0;[ ;{ ;IC;"Removes tracing for the specified command on the given global
variable and returns +nil+. If no command is specified,
removes all tracing for that variable and returns an array
containing the commands actually removed.
;T;[o;=
;3I"
overload;F;40;;;50;)I"!untrace_var(symbol [, cmd] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;TI"nil;T; @K;[ ;I"@return [Array, nil];T;0; @K;!F;6i ;>0;[[I"symbol[, cmd];T0; @K;[ ;I"Removes tracing for the specified command on the given global
variable and returns +nil+. If no command is specified,
removes all tracing for that variable and returns an array
containing the commands actually removed.
@overload untrace_var(symbol [, cmd] )
@return [Array, nil];T;0; @K;!F;"o;#;$T;%i;&i;'@$ ;(I"fstatic VALUE
f_untrace_var(int c, const VALUE *a, VALUE _)
{
return rb_f_untrace_var(c, a);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Complex;F;[[@c0;[[I"complex.c;Ti*;T;:Complex;0;[ ;{ ;IC;"DReturns x+i*y;
Complex(1, 2) #=> (1+2i)
Complex('1+2i') #=> (1+2i)
Complex(nil) #=> TypeError
Complex(1, nil) #=> TypeError
Complex(1, nil, exception: false) #=> nil
Complex('1+2', exception: false) #=> nil
Syntax of string form:
string form = extra spaces , complex , extra spaces ;
complex = real part | [ sign ] , imaginary part
| real part , sign , imaginary part
| rational , "@" , rational ;
real part = rational ;
imaginary part = imaginary unit | unsigned rational , imaginary unit ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
imaginary unit = "i" | "I" | "j" | "J" ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit };
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;
See String#to_c.
;T;[o;=
;3I"
overload;F;40;;;50;)I"%Complex(x[, y], exception: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Numeric;TI"nil;T; @m;[ ;I"@return [Numeric, nil];T;0; @m;!F;6i ;>0;[[I"x[, y];T0[I"exception:;TI" true;T; @m;[ ;I"Returns x+i*y;
Complex(1, 2) #=> (1+2i)
Complex('1+2i') #=> (1+2i)
Complex(nil) #=> TypeError
Complex(1, nil) #=> TypeError
Complex(1, nil, exception: false) #=> nil
Complex('1+2', exception: false) #=> nil
Syntax of string form:
string form = extra spaces , complex , extra spaces ;
complex = real part | [ sign ] , imaginary part
| real part , sign , imaginary part
| rational , "@" , rational ;
real part = rational ;
imaginary part = imaginary unit | unsigned rational , imaginary unit ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
imaginary unit = "i" | "I" | "j" | "J" ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit };
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;
See String#to_c.
@overload Complex(x[, y], exception: true)
@return [Numeric, nil];T;0; @m;!F;"o;#;$T;%i;&i(;'@$ ;(I"static VALUE
nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
{
VALUE a1, a2, opts = Qnil;
int raise = TRUE;
if (rb_scan_args(argc, argv, "11:", &a1, &a2, &opts) == 1) {
a2 = Qundef;
}
if (!NIL_P(opts)) {
raise = rb_opts_exception_p(opts, raise);
}
if (argc > 0 && CLASS_OF(a1) == rb_cComplex && a2 == Qundef) {
return a1;
}
return nucomp_convert(rb_cComplex, a1, a2, raise);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#BigDecimal;F;[[@c0;[[I" ext/bigdecimal/bigdecimal.c;Ti
;T;:BigDecimal;0;[ ;{ ;IC;"Create a new BigDecimal object.
initial:: The initial value, as an Integer, a Float, a Rational,
a BigDecimal, or a String.
If it is a String, spaces are ignored and unrecognized characters
terminate the value.
digits:: The number of significant digits, as an Integer. If omitted or 0,
the number of significant digits is determined from the initial
value.
The actual number of significant digits used in computation is
usually larger than the specified number.
exception:: Whether an exception should be raised on invalid arguments.
+true+ by default, if passed +false+, just returns +nil+
for invalid.
==== Exceptions
TypeError:: If the +initial+ type is neither Integer, Float,
Rational, nor BigDecimal, this exception is raised.
TypeError:: If the +digits+ is not an Integer, this exception is raised.
ArgumentError:: If +initial+ is a Float, and the +digits+ is larger than
Float::DIG + 1, this exception is raised.
ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+
value is omitted, this exception is raised.
;T;[o;=
;3I"
overload;F;40;;;50;)I"1BigDecimal(initial, digits, exception: true);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"initial;T0[I"digits;T0[I"exception:;TI" true;T; @;[ ;I"Create a new BigDecimal object.
initial:: The initial value, as an Integer, a Float, a Rational,
a BigDecimal, or a String.
If it is a String, spaces are ignored and unrecognized characters
terminate the value.
digits:: The number of significant digits, as an Integer. If omitted or 0,
the number of significant digits is determined from the initial
value.
The actual number of significant digits used in computation is
usually larger than the specified number.
exception:: Whether an exception should be raised on invalid arguments.
+true+ by default, if passed +false+, just returns +nil+
for invalid.
==== Exceptions
TypeError:: If the +initial+ type is neither Integer, Float,
Rational, nor BigDecimal, this exception is raised.
TypeError:: If the +digits+ is not an Integer, this exception is raised.
ArgumentError:: If +initial+ is a Float, and the +digits+ is larger than
Float::DIG + 1, this exception is raised.
ArgumentError:: If the +initial+ is a Float or Rational, and the +digits+
value is omitted, this exception is raised.
@overload BigDecimal(initial, digits, exception: true);T;0; @;!F;"o;#;$T;%iz
;&i
;'@$ ;(I"static VALUE
f_BigDecimal(int argc, VALUE *argv, VALUE self)
{
ENTER(1);
Real *pv;
VALUE obj;
if (argc > 0 && CLASS_OF(argv[0]) == rb_cBigDecimal) {
if (argc == 1 || (argc == 2 && RB_TYPE_P(argv[1], T_HASH))) return argv[0];
}
obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0);
pv = VpNewVarArg(argc, argv);
if (pv == NULL) return Qnil;
SAVE(pv);
if (ToValue(pv)) pv = VpCopy(NULL, pv);
RTYPEDDATA_DATA(obj) = pv;
RB_OBJ_FREEZE(obj);
return pv->obj = obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Rational;F;[[@c0;[[I"rational.c;Ti6;T;:
Rational;0;[ ;{ ;IC;"Returns +x/y+ or +arg+ as a Rational.
Rational(2, 3) #=> (2/3)
Rational(5) #=> (5/1)
Rational(0.5) #=> (1/2)
Rational(0.3) #=> (5404319552844595/18014398509481984)
Rational("2/3") #=> (2/3)
Rational("0.3") #=> (3/10)
Rational("10 cents") #=> ArgumentError
Rational(nil) #=> TypeError
Rational(1, nil) #=> TypeError
Rational("10 cents", exception: false) #=> nil
Syntax of the string form:
string form = extra spaces , rational , extra spaces ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;
See also String#to_r.
;T;[o;=
;3I"
overload;F;40;;;50;)I"$Rational(x, y, exception: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"x;T0[I"y;T0[I"exception:;TI" true;T; @o;=
;3I"
overload;F;40;;;50;)I"#Rational(arg, exception: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"arg;T0[I"exception:;TI" true;T; @;[ ;I"jReturns +x/y+ or +arg+ as a Rational.
Rational(2, 3) #=> (2/3)
Rational(5) #=> (5/1)
Rational(0.5) #=> (1/2)
Rational(0.3) #=> (5404319552844595/18014398509481984)
Rational("2/3") #=> (2/3)
Rational("0.3") #=> (3/10)
Rational("10 cents") #=> ArgumentError
Rational(nil) #=> TypeError
Rational(1, nil) #=> TypeError
Rational("10 cents", exception: false) #=> nil
Syntax of the string form:
string form = extra spaces , rational , extra spaces ;
rational = [ sign ] , unsigned rational ;
unsigned rational = numerator | numerator , "/" , denominator ;
numerator = integer part | fractional part | integer part , fractional part ;
denominator = digits ;
integer part = digits ;
fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
sign = "-" | "+" ;
digits = digit , { digit | "_" , digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
extra spaces = ? \s* ? ;
See also String#to_r.
@overload Rational(x, y, exception: true)
@return [nil]
@overload Rational(arg, exception: true)
@return [nil];T;0; @;!F;"o;#;$T;%i;&i5;'@$ ;(I"^static VALUE
nurat_f_rational(int argc, VALUE *argv, VALUE klass)
{
VALUE a1, a2, opts = Qnil;
int raise = TRUE;
if (rb_scan_args(argc, argv, "11:", &a1, &a2, &opts) == 1) {
a2 = Qundef;
}
if (!NIL_P(opts)) {
raise = rb_opts_exception_p(opts, raise);
}
return nurat_convert(rb_cRational, a1, a2, raise);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#callcc;F;[ ;[[I"cont.c;Ti;T;:callcc;0;[ ;{ ;IC;"Generates a Continuation object, which it passes to
the associated block. You need to require
'continuation'
before using this method. Performing a
cont.call
will cause the #callcc
to return (as will falling through the end of the block). The
value returned by the #callcc is the value of the
block, or the value passed to cont.call
. See
class Continuation for more details. Also see
Kernel#throw for an alternative mechanism for
unwinding a call stack.
;T;[o;=
;3I"
overload;F;40;;;50;)I"callcc;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I" cont;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"#@yield [cont]
@return [Object];T;0; @;!F;6i ;>0;[ ; @;[ ;I"4Generates a Continuation object, which it passes to
the associated block. You need to require
'continuation'
before using this method. Performing a
cont.call
will cause the #callcc
to return (as will falling through the end of the block). The
value returned by the #callcc is the value of the
block, or the value passed to cont.call
. See
class Continuation for more details. Also see
Kernel#throw for an alternative mechanism for
unwinding a call stack.
@overload callcc
@yield [cont]
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_callcc(VALUE self)
{
volatile int called;
volatile VALUE val = cont_capture(&called);
if (called) {
return val;
}
else {
return rb_yield(val);
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#syscall;F;[[@c0;[[@i#';T;:syscall;0;[ ;{ ;IC;"Calls the operating system function identified by _num_ and
returns the result of the function or raises SystemCallError if
it failed.
Arguments for the function can follow _num_. They must be either
+String+ objects or +Integer+ objects. A +String+ object is passed
as a pointer to the byte sequence. An +Integer+ object is passed
as an integer whose bit size is same as a pointer.
Up to nine parameters may be passed.
The function identified by _num_ is system
dependent. On some Unix systems, the numbers may be obtained from a
header file called syscall.h
.
syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
produces:
hello
Calling +syscall+ on a platform which does not have any way to
an arbitrary system function just fails with NotImplementedError.
*Note:*
+syscall+ is essentially unsafe and unportable.
Feel free to shoot your foot.
The DL (Fiddle) library is preferred for safer and a bit
more portable programming.
;T;[o;=
;3I"
overload;F;40;;;50;)I"syscall(num [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Integer;T; @;[ ;I"@return [Integer];T;0; @;!F;6i ;>0;[[I"num[, args...];T0; @;[ ;I"Calls the operating system function identified by _num_ and
returns the result of the function or raises SystemCallError if
it failed.
Arguments for the function can follow _num_. They must be either
+String+ objects or +Integer+ objects. A +String+ object is passed
as a pointer to the byte sequence. An +Integer+ object is passed
as an integer whose bit size is same as a pointer.
Up to nine parameters may be passed.
The function identified by _num_ is system
dependent. On some Unix systems, the numbers may be obtained from a
header file called syscall.h
.
syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
produces:
hello
Calling +syscall+ on a platform which does not have any way to
an arbitrary system function just fails with NotImplementedError.
*Note:*
+syscall+ is essentially unsafe and unportable.
Feel free to shoot your foot.
The DL (Fiddle) library is preferred for safer and a bit
more portable programming.
@overload syscall(num [, args...])
@return [Integer];T;0; @;!F;"o;#;$T;%i';&i ';'@$ ;(I", static VALUE
rb_f_syscall(int argc, VALUE *argv, VALUE _)
{
VALUE arg[8];
#if SIZEOF_VOIDP == 8 && defined(HAVE___SYSCALL) && SIZEOF_INT != 8 /* mainly *BSD */
# define SYSCALL __syscall
# define NUM2SYSCALLID(x) NUM2LONG(x)
# define RETVAL2NUM(x) LONG2NUM(x)
# if SIZEOF_LONG == 8
long num, retval = -1;
# elif SIZEOF_LONG_LONG == 8
long long num, retval = -1;
# else
# error ---->> it is asserted that __syscall takes the first argument and returns retval in 64bit signed integer. <<----
# endif
#elif defined(__linux__)
# define SYSCALL syscall
# define NUM2SYSCALLID(x) NUM2LONG(x)
# define RETVAL2NUM(x) LONG2NUM(x)
/*
* Linux man page says, syscall(2) function prototype is below.
*
* int syscall(int number, ...);
*
* But, it's incorrect. Actual one takes and returned long. (see unistd.h)
*/
long num, retval = -1;
#else
# define SYSCALL syscall
# define NUM2SYSCALLID(x) NUM2INT(x)
# define RETVAL2NUM(x) INT2NUM(x)
int num, retval = -1;
#endif
int i;
if (RTEST(ruby_verbose)) {
rb_warning("We plan to remove a syscall function at future release. DL(Fiddle) provides safer alternative.");
}
if (argc == 0)
rb_raise(rb_eArgError, "too few arguments for syscall");
if (argc > numberof(arg))
rb_raise(rb_eArgError, "too many arguments for syscall");
num = NUM2SYSCALLID(argv[0]); ++argv;
for (i = argc - 1; i--; ) {
VALUE v = rb_check_string_type(argv[i]);
if (!NIL_P(v)) {
SafeStringValue(v);
rb_str_modify(v);
arg[i] = (VALUE)StringValueCStr(v);
}
else {
arg[i] = (VALUE)NUM2LONG(argv[i]);
}
}
switch (argc) {
case 1:
retval = SYSCALL(num);
break;
case 2:
retval = SYSCALL(num, arg[0]);
break;
case 3:
retval = SYSCALL(num, arg[0],arg[1]);
break;
case 4:
retval = SYSCALL(num, arg[0],arg[1],arg[2]);
break;
case 5:
retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3]);
break;
case 6:
retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4]);
break;
case 7:
retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5]);
break;
case 8:
retval = SYSCALL(num, arg[0],arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]);
break;
}
if (retval == -1)
rb_sys_fail(0);
return RETVAL2NUM(retval);
#undef SYSCALL
#undef NUM2SYSCALLID
#undef RETVAL2NUM
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#open;F;[[@c0;[[@i;T;: open;0;[ ;{ ;IC;" Creates an IO object connected to the given stream, file, or subprocess.
If +path+ does not start with a pipe character (|
), treat it
as the name of a file to open using the specified mode (defaulting to
"r").
The +mode+ is either a string or an integer. If it is an integer, it
must be bitwise-or of open(2) flags, such as File::RDWR or File::EXCL. If
it is a string, it is either "fmode", "fmode:ext_enc", or
"fmode:ext_enc:int_enc".
See the documentation of IO.new for full documentation of the +mode+ string
directives.
If a file is being created, its initial permissions may be set using the
+perm+ parameter. See File.new and the open(2) and chmod(2) man pages for
a description of permissions.
If a block is specified, it will be invoked with the IO object as a
parameter, and the IO will be automatically closed when the block
terminates. The call returns the value of the block.
If +path+ starts with a pipe character ("|"
), a subprocess is
created, connected to the caller by a pair of pipes. The returned IO
object may be used to write to the standard input and read from the
standard output of this subprocess.
If the command following the pipe is a single minus sign
("|-"
), Ruby forks, and this subprocess is connected to the
parent. If the command is not "-"
, the subprocess runs the
command.
When the subprocess is Ruby (opened via "|-"
), the +open+
call returns +nil+. If a block is associated with the open call, that
block will run twice --- once in the parent and once in the child.
The block parameter will be an IO object in the parent and +nil+ in the
child. The parent's +IO+ object will be connected to the child's $stdin
and $stdout. The subprocess will be terminated at the end of the block.
=== Examples
Reading from "testfile":
open("testfile") do |f|
print f.gets
end
Produces:
This is line one
Open a subprocess and read its output:
cmd = open("|date")
print cmd.gets
cmd.close
Produces:
Wed Apr 9 08:56:31 CDT 2003
Open a subprocess running the same Ruby program:
f = open("|-", "w+")
if f.nil?
puts "in Child"
exit
else
puts "Got: #{f.gets}"
end
Produces:
Got: in Child
Open a subprocess using a block to receive the IO object:
open "|-" do |f|
if f then
# parent process
puts "Got: #{f.gets}"
else
# child process
puts "in Child"
end
end
Produces:
Got: in Child
;T;[o;=
;3I"
overload;F;40;;;50;)I")open(path [, mode [, perm]] [, opt]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"IO;TI"nil;T; @$;[ ;I"@return [IO, nil];T;0; @$;!F;6i ;>0;[[I"!path[, mode [, perm]][, opt];T0; @$o;=
;3I"
overload;F;40;;;50;)I")open(path [, mode [, perm]] [, opt]);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"io;T; @$o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @$;[ ;I"!@yield [io]
@return [Object];T;0; @$;!F;6i ;>0;[[I"!path[, mode [, perm]][, opt];T0; @$;[ ;I"\
Creates an IO object connected to the given stream, file, or subprocess.
If +path+ does not start with a pipe character (|
), treat it
as the name of a file to open using the specified mode (defaulting to
"r").
The +mode+ is either a string or an integer. If it is an integer, it
must be bitwise-or of open(2) flags, such as File::RDWR or File::EXCL. If
it is a string, it is either "fmode", "fmode:ext_enc", or
"fmode:ext_enc:int_enc".
See the documentation of IO.new for full documentation of the +mode+ string
directives.
If a file is being created, its initial permissions may be set using the
+perm+ parameter. See File.new and the open(2) and chmod(2) man pages for
a description of permissions.
If a block is specified, it will be invoked with the IO object as a
parameter, and the IO will be automatically closed when the block
terminates. The call returns the value of the block.
If +path+ starts with a pipe character ("|"
), a subprocess is
created, connected to the caller by a pair of pipes. The returned IO
object may be used to write to the standard input and read from the
standard output of this subprocess.
If the command following the pipe is a single minus sign
("|-"
), Ruby forks, and this subprocess is connected to the
parent. If the command is not "-"
, the subprocess runs the
command.
When the subprocess is Ruby (opened via "|-"
), the +open+
call returns +nil+. If a block is associated with the open call, that
block will run twice --- once in the parent and once in the child.
The block parameter will be an IO object in the parent and +nil+ in the
child. The parent's +IO+ object will be connected to the child's $stdin
and $stdout. The subprocess will be terminated at the end of the block.
=== Examples
Reading from "testfile":
open("testfile") do |f|
print f.gets
end
Produces:
This is line one
Open a subprocess and read its output:
cmd = open("|date")
print cmd.gets
cmd.close
Produces:
Wed Apr 9 08:56:31 CDT 2003
Open a subprocess running the same Ruby program:
f = open("|-", "w+")
if f.nil?
puts "in Child"
exit
else
puts "Got: #{f.gets}"
end
Produces:
Got: in Child
Open a subprocess using a block to receive the IO object:
open "|-" do |f|
if f then
# parent process
puts "Got: #{f.gets}"
else
# child process
puts "in Child"
end
end
Produces:
Got: in Child
@overload open(path [, mode [, perm]] [, opt])
@return [IO, nil]
@overload open(path [, mode [, perm]] [, opt])
@yield [io]
@return [Object];T;0; @$;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_open(int argc, VALUE *argv, VALUE _)
{
ID to_open = 0;
int redirect = FALSE;
if (argc >= 1) {
CONST_ID(to_open, "to_open");
if (rb_respond_to(argv[0], to_open)) {
redirect = TRUE;
}
else {
VALUE tmp = argv[0];
FilePathValue(tmp);
if (NIL_P(tmp)) {
redirect = TRUE;
}
else {
VALUE cmd = check_pipe_command(tmp);
if (!NIL_P(cmd)) {
argv[0] = cmd;
return rb_io_s_popen(argc, argv, rb_cIO);
}
}
}
}
if (redirect) {
VALUE io = rb_funcallv_kw(argv[0], to_open, argc-1, argv+1, RB_PASS_CALLED_KEYWORDS);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, io, io_close, io);
}
return io;
}
return rb_io_s_open(argc, argv, rb_cFile);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#printf;F;[[@c0;[[@if;T;:printf;0;[ ;{ ;IC;"iEquivalent to:
io.write(sprintf(string, obj, ...))
or
$stdout.write(sprintf(string, obj, ...))
;T;[o;=
;3I"
overload;F;40;;;50;)I"$printf(io, string [, obj ... ]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @W;[ ;I"@return [nil];T;0; @W;!F;6i ;>0;[[I"io;T0[I"string[, obj ... ];T0; @Wo;=
;3I"
overload;F;40;;;50;)I" printf(string [, obj ... ]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @W;[ ;I"@return [nil];T;0; @W;!F;6i ;>0;[[I"string[, obj ... ];T0; @W;[ ;I"Equivalent to:
io.write(sprintf(string, obj, ...))
or
$stdout.write(sprintf(string, obj, ...))
@overload printf(io, string [, obj ... ])
@return [nil]
@overload printf(string [, obj ... ])
@return [nil];T;0; @W;!F;"o;#;$T;%i[;&id;'@$ ;(I"!static VALUE
rb_f_printf(int argc, VALUE *argv, VALUE _)
{
VALUE out;
if (argc == 0) return Qnil;
if (RB_TYPE_P(argv[0], T_STRING)) {
out = rb_stdout;
}
else {
out = argv[0];
argv++;
argc--;
}
rb_io_write(out, rb_f_sprintf(argc, argv));
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#print;F;[[@c0;[[@i;T;:
print;0;[ ;{ ;IC;"Prints each object in turn to $stdout
. If the output
field separator ($,
) is not +nil+, its
contents will appear between each field. If the output record
separator ($\\
) is not +nil+, it will be
appended to the output. If no arguments are given, prints
$_
. Objects that aren't strings will be converted by
calling their to_s
method.
print "cat", [1,2,3], 99, "\n"
$, = ", "
$\ = "\n"
print "cat", [1,2,3], 99
produces:
cat12399
cat, 1, 2, 3, 99
;T;[o;=
;3I"
overload;F;40;;;50;)I"print(obj, ...);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"obj;T0[I"...;T0; @;[ ;I"GPrints each object in turn to $stdout
. If the output
field separator ($,
) is not +nil+, its
contents will appear between each field. If the output record
separator ($\\
) is not +nil+, it will be
appended to the output. If no arguments are given, prints
$_
. Objects that aren't strings will be converted by
calling their to_s
method.
print "cat", [1,2,3], 99, "\n"
$, = ", "
$\ = "\n"
print "cat", [1,2,3], 99
produces:
cat12399
cat, 1, 2, 3, 99
@overload print(obj, ...)
@return [nil];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_print(int argc, const VALUE *argv, VALUE _)
{
rb_io_print(argc, argv, rb_stdout);
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#putc;F;[[I"ch;T0;[[@i;T;: putc;0;[ ;{ ;IC;"Equivalent to:
$stdout.putc(int)
Refer to the documentation for IO#putc for important information regarding
multi-byte characters.
;T;[o;=
;3I"
overload;F;40;;;50;)I"putc(int);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Integer;T; @;[ ;I"@return [Integer];T;0; @;!F;6i ;>0;[[I"int;T0; @;[ ;I"Equivalent to:
$stdout.putc(int)
Refer to the documentation for IO#putc for important information regarding
multi-byte characters.
@overload putc(int)
@return [Integer];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_putc(VALUE recv, VALUE ch)
{
if (recv == rb_stdout) {
return rb_io_putc(recv, ch);
}
return rb_funcallv(rb_stdout, rb_intern("putc"), 1, &ch);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#puts;F;[[@c0;[[@ip;T;: puts;0;[ ;{ ;IC;".Equivalent to
$stdout.puts(obj, ...)
;T;[o;=
;3I"
overload;F;40;;;50;)I"puts(obj, ...);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @;[ ;I"@return [nil];T;0; @;!F;6i ;>0;[[I"obj;T0[I"...;T0; @;[ ;I"YEquivalent to
$stdout.puts(obj, ...)
@overload puts(obj, ...)
@return [nil];T;0; @;!F;"o;#;$T;%ig;&im;'@$ ;(I"static VALUE
rb_f_puts(int argc, VALUE *argv, VALUE recv)
{
if (recv == rb_stdout) {
return rb_io_puts(argc, argv, recv);
}
return rb_funcallv(rb_stdout, rb_intern("puts"), argc, argv);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#gets;F;[[@c0;[[@i";T;: gets;0;[ ;{ ;IC;"Returns (and assigns to $_
) the next line from the list
of files in +ARGV+ (or $*
), or from standard input if
no files are present on the command line. Returns +nil+ at end of
file. The optional argument specifies the record separator. The
separator is included with the contents of each record. A separator
of +nil+ reads the entire contents, and a zero-length separator
reads the input one paragraph at a time, where paragraphs are
divided by two consecutive newlines. 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. If multiple
filenames are present in +ARGV+, gets(nil)
will read
the contents one file at a time.
ARGV << "testfile"
print while gets
produces:
This is line one
This is line two
This is line three
And so on...
The style of programming using $_
as an implicit
parameter is gradually losing favor in the Ruby community.
;T;[o;=
;3I"
overload;F;40;;;50;)I""gets(sep=$/ [, getline_args]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;TI"nil;T; @;[ ;I"@return [String, nil];T;0; @;!F;6i ;>0;[[I"sep;TI"$/[, getline_args];T; @o;=
;3I"
overload;F;40;;;50;)I"!gets(limit [, getline_args]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;TI"nil;T; @;[ ;I"@return [String, nil];T;0; @;!F;6i ;>0;[[I"limit[, getline_args];T0; @o;=
;3I"
overload;F;40;;;50;)I"&gets(sep, limit [, getline_args]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;TI"nil;T; @;[ ;I"@return [String, nil];T;0; @;!F;6i ;>0;[[I"sep;T0[I"limit[, getline_args];T0; @;[ ;I"Returns (and assigns to $_
) the next line from the list
of files in +ARGV+ (or $*
), or from standard input if
no files are present on the command line. Returns +nil+ at end of
file. The optional argument specifies the record separator. The
separator is included with the contents of each record. A separator
of +nil+ reads the entire contents, and a zero-length separator
reads the input one paragraph at a time, where paragraphs are
divided by two consecutive newlines. 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. If multiple
filenames are present in +ARGV+, gets(nil)
will read
the contents one file at a time.
ARGV << "testfile"
print while gets
produces:
This is line one
This is line two
This is line three
And so on...
The style of programming using $_
as an implicit
parameter is gradually losing favor in the Ruby community.
@overload gets(sep=$/ [, getline_args])
@return [String, nil]
@overload gets(limit [, getline_args])
@return [String, nil]
@overload gets(sep, limit [, getline_args])
@return [String, nil];T;0; @;!F;"o;#;$T;%i";&i";'@$ ;(I"static VALUE
rb_f_gets(int argc, VALUE *argv, VALUE recv)
{
if (recv == argf) {
return argf_gets(argc, argv, argf);
}
return rb_funcallv(argf, idGets, argc, argv);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#readline;F;[[@c0;[[@i";T;:
readline;0;[ ;{ ;IC;"TEquivalent to Kernel::gets, except
+readline+ raises +EOFError+ at end of file.
;T;[o;=
;3I"
overload;F;40;;;50;)I"readline(sep=$/);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @'
;[ ;I"@return [String];T;0; @'
;!F;6i ;>0;[[I"sep;TI"$/;T; @'
o;=
;3I"
overload;F;40;;;50;)I"readline(limit);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @'
;[ ;I"@return [String];T;0; @'
;!F;6i ;>0;[[I"
limit;T0; @'
o;=
;3I"
overload;F;40;;;50;)I"readline(sep, limit);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @'
;[ ;I"@return [String];T;0; @'
;!F;6i ;>0;[[I"sep;T0[I"
limit;T0; @'
;[ ;I"Equivalent to Kernel::gets, except
+readline+ raises +EOFError+ at end of file.
@overload readline(sep=$/)
@return [String]
@overload readline(limit)
@return [String]
@overload readline(sep, limit)
@return [String];T;0; @'
;!F;"o;#;$T;%i";&i";'@$ ;(I"static VALUE
rb_f_readline(int argc, VALUE *argv, VALUE recv)
{
if (recv == argf) {
return argf_readline(argc, argv, argf);
}
return rb_funcallv(argf, rb_intern("readline"), argc, argv);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#select;F;[[@c0;[[@iN%;T;:select;0;[ ;{ ;IC;"Calls select(2) system call.
It monitors given arrays of IO objects, waits until one or more of
IO objects are ready for reading, are ready for writing, and have
pending exceptions respectively, and returns an array that contains
arrays of those IO objects. It will return +nil+ if optional
timeout value is given and no IO object is ready in
timeout seconds.
IO.select peeks the buffer of IO objects for testing readability.
If the IO buffer is not empty, IO.select immediately notifies
readability. This "peek" only happens for IO objects. It does not
happen for IO-like objects such as OpenSSL::SSL::SSLSocket.
The best way to use IO.select is invoking it after nonblocking
methods such as #read_nonblock, #write_nonblock, etc. The methods
raise an exception which is extended by IO::WaitReadable or
IO::WaitWritable. The modules notify how the caller should wait
with IO.select. If IO::WaitReadable is raised, the caller should
wait for reading. If IO::WaitWritable is raised, the caller should
wait for writing.
So, blocking read (#readpartial) can be emulated using
#read_nonblock and IO.select as follows:
begin
result = io_like.read_nonblock(maxlen)
rescue IO::WaitReadable
IO.select([io_like])
retry
rescue IO::WaitWritable
IO.select(nil, [io_like])
retry
end
Especially, the combination of nonblocking methods and IO.select is
preferred for IO like objects such as OpenSSL::SSL::SSLSocket. It
has #to_io method to return underlying IO object. IO.select calls
#to_io to obtain the file descriptor to wait.
This means that readability notified by IO.select doesn't mean
readability from OpenSSL::SSL::SSLSocket object.
The most likely situation is that OpenSSL::SSL::SSLSocket buffers
some data. IO.select doesn't see the buffer. So IO.select can
block when OpenSSL::SSL::SSLSocket#readpartial doesn't block.
However, several more complicated situations exist.
SSL is a protocol which is sequence of records.
The record consists of multiple bytes.
So, the remote side of SSL sends a partial record, IO.select
notifies readability but OpenSSL::SSL::SSLSocket cannot decrypt a
byte and OpenSSL::SSL::SSLSocket#readpartial will block.
Also, the remote side can request SSL renegotiation which forces
the local SSL engine to write some data.
This means OpenSSL::SSL::SSLSocket#readpartial may invoke #write
system call and it can block.
In such a situation, OpenSSL::SSL::SSLSocket#read_nonblock raises
IO::WaitWritable instead of blocking.
So, the caller should wait for ready for writability as above
example.
The combination of nonblocking methods and IO.select is also useful
for streams such as tty, pipe socket socket when multiple processes
read from a stream.
Finally, Linux kernel developers don't guarantee that
readability of select(2) means readability of following read(2) even
for a single process.
See select(2) manual on GNU/Linux system.
Invoking IO.select before IO#readpartial works well as usual.
However it is not the best way to use IO.select.
The writability notified by select(2) doesn't show
how many bytes are writable.
IO#write method blocks until given whole string is written.
So, IO#write(two or more bytes)
can block after
writability is notified by IO.select. IO#write_nonblock is required
to avoid the blocking.
Blocking write (#write) can be emulated using #write_nonblock and
IO.select as follows: IO::WaitReadable should also be rescued for
SSL renegotiation in OpenSSL::SSL::SSLSocket.
while 0 < string.bytesize
begin
written = io_like.write_nonblock(string)
rescue IO::WaitReadable
IO.select([io_like])
retry
rescue IO::WaitWritable
IO.select(nil, [io_like])
retry
end
string = string.byteslice(written..-1)
end
=== Parameters
read_array:: an array of IO objects that wait until ready for read
write_array:: an array of IO objects that wait until ready for write
error_array:: an array of IO objects that wait for exceptions
timeout:: a numeric value in second
=== Example
rp, wp = IO.pipe
mesg = "ping "
100.times {
# IO.select follows IO#read. Not the best way to use IO.select.
rs, ws, = IO.select([rp], [wp])
if r = rs[0]
ret = r.read(5)
print ret
case ret
when /ping/
mesg = "pong\n"
when /pong/
mesg = "ping "
end
end
if w = ws[0]
w.write(mesg)
end
}
produces:
ping pong
ping pong
ping pong
(snipped)
ping
;T;[o;=
;3I"
overload;F;40;;;50;)I"Cselect(read_array [, write_array [, error_array [, timeout]]]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;TI"nil;T; @f
;[ ;I"@return [Array, nil];T;0; @f
;!F;6i ;>0;[[I":read_array[, write_array [, error_array [, timeout]]];T0; @f
;[ ;I"+Calls select(2) system call.
It monitors given arrays of IO objects, waits until one or more of
IO objects are ready for reading, are ready for writing, and have
pending exceptions respectively, and returns an array that contains
arrays of those IO objects. It will return +nil+ if optional
timeout value is given and no IO object is ready in
timeout seconds.
IO.select peeks the buffer of IO objects for testing readability.
If the IO buffer is not empty, IO.select immediately notifies
readability. This "peek" only happens for IO objects. It does not
happen for IO-like objects such as OpenSSL::SSL::SSLSocket.
The best way to use IO.select is invoking it after nonblocking
methods such as #read_nonblock, #write_nonblock, etc. The methods
raise an exception which is extended by IO::WaitReadable or
IO::WaitWritable. The modules notify how the caller should wait
with IO.select. If IO::WaitReadable is raised, the caller should
wait for reading. If IO::WaitWritable is raised, the caller should
wait for writing.
So, blocking read (#readpartial) can be emulated using
#read_nonblock and IO.select as follows:
begin
result = io_like.read_nonblock(maxlen)
rescue IO::WaitReadable
IO.select([io_like])
retry
rescue IO::WaitWritable
IO.select(nil, [io_like])
retry
end
Especially, the combination of nonblocking methods and IO.select is
preferred for IO like objects such as OpenSSL::SSL::SSLSocket. It
has #to_io method to return underlying IO object. IO.select calls
#to_io to obtain the file descriptor to wait.
This means that readability notified by IO.select doesn't mean
readability from OpenSSL::SSL::SSLSocket object.
The most likely situation is that OpenSSL::SSL::SSLSocket buffers
some data. IO.select doesn't see the buffer. So IO.select can
block when OpenSSL::SSL::SSLSocket#readpartial doesn't block.
However, several more complicated situations exist.
SSL is a protocol which is sequence of records.
The record consists of multiple bytes.
So, the remote side of SSL sends a partial record, IO.select
notifies readability but OpenSSL::SSL::SSLSocket cannot decrypt a
byte and OpenSSL::SSL::SSLSocket#readpartial will block.
Also, the remote side can request SSL renegotiation which forces
the local SSL engine to write some data.
This means OpenSSL::SSL::SSLSocket#readpartial may invoke #write
system call and it can block.
In such a situation, OpenSSL::SSL::SSLSocket#read_nonblock raises
IO::WaitWritable instead of blocking.
So, the caller should wait for ready for writability as above
example.
The combination of nonblocking methods and IO.select is also useful
for streams such as tty, pipe socket socket when multiple processes
read from a stream.
Finally, Linux kernel developers don't guarantee that
readability of select(2) means readability of following read(2) even
for a single process.
See select(2) manual on GNU/Linux system.
Invoking IO.select before IO#readpartial works well as usual.
However it is not the best way to use IO.select.
The writability notified by select(2) doesn't show
how many bytes are writable.
IO#write method blocks until given whole string is written.
So, IO#write(two or more bytes)
can block after
writability is notified by IO.select. IO#write_nonblock is required
to avoid the blocking.
Blocking write (#write) can be emulated using #write_nonblock and
IO.select as follows: IO::WaitReadable should also be rescued for
SSL renegotiation in OpenSSL::SSL::SSLSocket.
while 0 < string.bytesize
begin
written = io_like.write_nonblock(string)
rescue IO::WaitReadable
IO.select([io_like])
retry
rescue IO::WaitWritable
IO.select(nil, [io_like])
retry
end
string = string.byteslice(written..-1)
end
=== Parameters
read_array:: an array of IO objects that wait until ready for read
write_array:: an array of IO objects that wait until ready for write
error_array:: an array of IO objects that wait for exceptions
timeout:: a numeric value in second
=== Example
rp, wp = IO.pipe
mesg = "ping "
100.times {
# IO.select follows IO#read. Not the best way to use IO.select.
rs, ws, = IO.select([rp], [wp])
if r = rs[0]
ret = r.read(5)
print ret
case ret
when /ping/
mesg = "pong\n"
when /pong/
mesg = "ping "
end
end
if w = ws[0]
w.write(mesg)
end
}
produces:
ping pong
ping pong
ping pong
(snipped)
ping
@overload select(read_array [, write_array [, error_array [, timeout]]])
@return [Array, nil];T;0; @f
;!F;"o;#;$T;%i$;&iK%;'@$ ;(I"
static VALUE
rb_f_select(int argc, VALUE *argv, VALUE obj)
{
VALUE timeout;
struct select_args args;
struct timeval timerec;
int i;
rb_scan_args(argc, argv, "13", &args.read, &args.write, &args.except, &timeout);
if (NIL_P(timeout)) {
args.timeout = 0;
}
else {
timerec = rb_time_interval(timeout);
args.timeout = &timerec;
}
for (i = 0; i < numberof(args.fdsets); ++i)
rb_fd_init(&args.fdsets[i]);
return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#readlines;F;[[@c0;[[@i%#;T;:readlines;0;[ ;{ ;IC;"zReturns an array containing the lines returned by calling
Kernel.gets(sep)
until the end of file.
;T;[o;=
;3I"
overload;F;40;;;50;)I"readlines(sep=$/);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @
;[ ;I"@return [Array];T;0; @
;!F;6i ;>0;[[I"sep;TI"$/;T; @
o;=
;3I"
overload;F;40;;;50;)I"readlines(limit);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @
;[ ;I"@return [Array];T;0; @
;!F;6i ;>0;[[I"
limit;T0; @
o;=
;3I"
overload;F;40;;;50;)I"readlines(sep, limit);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @
;[ ;I"@return [Array];T;0; @
;!F;6i ;>0;[[I"sep;T0[I"
limit;T0; @
;[ ;I"Returns an array containing the lines returned by calling
Kernel.gets(sep)
until the end of file.
@overload readlines(sep=$/)
@return [Array]
@overload readlines(limit)
@return [Array]
@overload readlines(sep, limit)
@return [Array];T;0; @
;!F;"o;#;$T;%i#;&i$#;'@$ ;(I"static VALUE
rb_f_readlines(int argc, VALUE *argv, VALUE recv)
{
if (recv == argf) {
return argf_readlines(argc, argv, argf);
}
return rb_funcallv(argf, rb_intern("readlines"), argc, argv);
};T;)I"static VALUE;T;*To;;F;
;;;;I"
Kernel#`;F;[[I"str;T0;[[@id#;T;:`;0;[ ;{ ;IC;"ZReturns the standard output of running _cmd_ in a subshell.
The built-in syntax %x{...}
uses
this method. Sets $?
to the process status.
`date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"
`ls testdir`.split[1] #=> "main.rb"
`echo oops && exit 99` #=> "oops\n"
$?.exitstatus #=> 99
;T;[o;=
;3I"
overload;F;40;;;50;)I"
`cmd`;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @
;[ ;I"@return [String];T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"Returns the standard output of running _cmd_ in a subshell.
The built-in syntax %x{...}
uses
this method. Sets $?
to the process status.
`date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"
`ls testdir`.split[1] #=> "main.rb"
`echo oops && exit 99` #=> "oops\n"
$?.exitstatus #=> 99
@overload `cmd`
@return [String];T;0; @
;!F;"o;#;$T;%iV#;&ia#;'@$ ;(I"static VALUE
rb_f_backquote(VALUE obj, VALUE str)
{
VALUE port;
VALUE result;
rb_io_t *fptr;
SafeStringValue(str);
rb_last_status_clear();
port = pipe_open_s(str, "r", FMODE_READABLE|DEFAULT_TEXTMODE, NULL);
if (NIL_P(port)) return rb_str_new(0,0);
GetOpenFile(port, fptr);
result = read_all(fptr, remain_size(fptr), Qnil);
rb_io_close(port);
RFILE(port)->fptr = NULL;
rb_io_fptr_finalize(fptr);
rb_gc_force_recycle(port); /* also guards from premature GC */
return result;
};T;)I"static VALUE;T;*To;;F;
;;;;I"
Kernel#p;F;[[@c0;[[@i;T;:p;0;[ ;{ ;IC;"For each object, directly writes _obj_.+inspect+ followed by a
newline to the program's standard output.
S = Struct.new(:name, :state)
s = S['dave', 'TX']
p s
produces:
#
;T;[o;=
;3I"
overload;F;40;;;50;)I"p(obj);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @
;[ ;I"@return [Object];T;0; @
;!F;6i ;>0;[[I"obj;T0; @
o;=
;3I"
overload;F;40;;;50;)I"p(obj1, obj2, ...);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @
;[ ;I"@return [Array];T;0; @
;!F;6i ;>0;[[I" obj1;T0[I" obj2;T0[I"...;T0; @
o;=
;3I"
overload;F;40;;;50;)I"p();T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"nil;T; @
;[ ;I"@return [nil];T;0; @
;!F;6i ;>0;[ ; @
;[ ;I"PFor each object, directly writes _obj_.+inspect+ followed by a
newline to the program's standard output.
S = Struct.new(:name, :state)
s = S['dave', 'TX']
p s
produces:
#
@overload p(obj)
@return [Object]
@overload p(obj1, obj2, ...)
@return [Array]
@overload p()
@return [nil];T;0; @
;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_p(int argc, VALUE *argv, VALUE self)
{
struct rb_f_p_arg arg;
arg.argc = argc;
arg.argv = argv;
return rb_uninterruptible(rb_f_p_internal, (VALUE)&arg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#trap;F;[[@c0;[[I"
signal.c;TiY;T;: trap;0;[ ;{ ;IC;"Specifies the handling of signals. The first parameter is a signal
name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
signal number. The characters ``SIG'' may be omitted from the
signal name. The command or block specifies code to be run when the
signal is raised.
If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
will be ignored.
If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
will be invoked.
If the command is ``EXIT'', the script will be terminated by the signal.
If the command is ``SYSTEM_DEFAULT'', the operating system's default
handler will be invoked.
Otherwise, the given command or block will be run.
The special signal name ``EXIT'' or signal number zero will be
invoked just prior to program termination.
trap returns the previous handler for the given signal.
Signal.trap(0, proc { puts "Terminating: #{$$}" })
Signal.trap("CLD") { puts "Child died" }
fork && Process.wait
produces:
Terminating: 27461
Child died
Terminating: 27460
;T;[o;=
;3I"
overload;F;40;;;50;)I"trap( signal, command );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"signal;T0[I"command;T0; @o;=
;3I"
overload;F;40;;;50;)I"trap( signal );T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I" ;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I" @yield [ ]
@return [Object];T;0; @;!F;6i ;>0;[[I"signal;T0; @;[ ;I"xSpecifies the handling of signals. The first parameter is a signal
name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
signal number. The characters ``SIG'' may be omitted from the
signal name. The command or block specifies code to be run when the
signal is raised.
If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
will be ignored.
If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
will be invoked.
If the command is ``EXIT'', the script will be terminated by the signal.
If the command is ``SYSTEM_DEFAULT'', the operating system's default
handler will be invoked.
Otherwise, the given command or block will be run.
The special signal name ``EXIT'' or signal number zero will be
invoked just prior to program termination.
trap returns the previous handler for the given signal.
Signal.trap(0, proc { puts "Terminating: #{$$}" })
Signal.trap("CLD") { puts "Child died" }
fork && Process.wait
produces:
Terminating: 27461
Child died
Terminating: 27460
@overload trap( signal, command )
@return [Object]
@overload trap( signal )
@yield [ ]
@return [Object];T;0; @;!F;"o;#;$T;%i:;&iY;'@$ ;(I"gstatic VALUE
sig_trap(int argc, VALUE *argv, VALUE _)
{
int sig;
sighandler_t func;
VALUE cmd;
rb_check_arity(argc, 1, 2);
sig = trap_signm(argv[0]);
if (reserved_signal_p(sig)) {
const char *name = signo2signm(sig);
if (name)
rb_raise(rb_eArgError, "can't trap reserved signal: SIG%s", name);
else
rb_raise(rb_eArgError, "can't trap reserved signal: %d", sig);
}
if (argc == 1) {
cmd = rb_block_proc();
func = sighandler;
}
else {
cmd = argv[1];
func = trap_handler(&cmd, sig);
}
return trap(sig, func, cmd);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#exec;F;[[I"*a;T0[I"_;T0;[[I"process.c;Ti;T;: exec;0;[ ;{ ;IC;"4
Replaces the current process by running the given external _command_, which
can take one of the following forms:
[exec(commandline)
]
command line string which is passed to the standard shell
[exec(cmdname, arg1, ...)
]
command name and one or more arguments (no shell)
[exec([cmdname, argv0], arg1, ...)
]
command name, argv[0] and zero or more arguments (no shell)
In the first form, the string is taken as a command line that is subject to
shell expansion before being executed.
The standard shell always means "/bin/sh"
on Unix-like systems,
same as ENV["RUBYSHELL"]
(or ENV["COMSPEC"]
on Windows NT series), and similar.
If the string from the first form (exec("command")
) follows
these simple rules:
* no meta characters
* no shell reserved word and no special built-in
* Ruby invokes the command directly without shell
You can force shell invocation by adding ";" to the string (because ";" is
a meta character).
Note that this behavior is observable by pid obtained
(return value of spawn() and IO#pid for IO.popen) is the pid of the invoked
command, not shell.
In the second form (exec("command1", "arg1", ...)
), the first
is taken as a command name and the rest are passed as parameters to command
with no shell expansion.
In the third form (exec(["command", "argv0"], "arg1", ...)
),
starting a two-element array at the beginning of the command, the first
element is the command to be executed, and the second argument is used as
the argv[0]
value, which may show up in process listings.
In order to execute the command, one of the exec(2)
system
calls are used, so the running command may inherit some of the environment
of the original program (including open file descriptors).
This behavior is modified by the given +env+ and +options+ parameters. See
::spawn for details.
If the command fails to execute (typically Errno::ENOENT when
it was not found) a SystemCallError exception is raised.
This method modifies process attributes according to given +options+ before
exec(2)
system call. See ::spawn for more details about the
given +options+.
The modified attributes may be retained when exec(2)
system
call fails.
For example, hard resource limits are not restorable.
Consider to create a child process using ::spawn or Kernel#system if this
is not acceptable.
exec "echo *" # echoes list of files in current directory
# never get here
exec "echo", "*" # echoes an asterisk
# never get here
;T;[o;=
;3I"
overload;F;40;;;50;)I"'exec([env,] command... [,options]);T;IC;" ;T;[ ;[ ;I" ;T;0; @T;!F;6i ;>0;[[I"[env,][,options];T0; @T;[ ;I"c
Replaces the current process by running the given external _command_, which
can take one of the following forms:
[exec(commandline)
]
command line string which is passed to the standard shell
[exec(cmdname, arg1, ...)
]
command name and one or more arguments (no shell)
[exec([cmdname, argv0], arg1, ...)
]
command name, argv[0] and zero or more arguments (no shell)
In the first form, the string is taken as a command line that is subject to
shell expansion before being executed.
The standard shell always means "/bin/sh"
on Unix-like systems,
same as ENV["RUBYSHELL"]
(or ENV["COMSPEC"]
on Windows NT series), and similar.
If the string from the first form (exec("command")
) follows
these simple rules:
* no meta characters
* no shell reserved word and no special built-in
* Ruby invokes the command directly without shell
You can force shell invocation by adding ";" to the string (because ";" is
a meta character).
Note that this behavior is observable by pid obtained
(return value of spawn() and IO#pid for IO.popen) is the pid of the invoked
command, not shell.
In the second form (exec("command1", "arg1", ...)
), the first
is taken as a command name and the rest are passed as parameters to command
with no shell expansion.
In the third form (exec(["command", "argv0"], "arg1", ...)
),
starting a two-element array at the beginning of the command, the first
element is the command to be executed, and the second argument is used as
the argv[0]
value, which may show up in process listings.
In order to execute the command, one of the exec(2)
system
calls are used, so the running command may inherit some of the environment
of the original program (including open file descriptors).
This behavior is modified by the given +env+ and +options+ parameters. See
::spawn for details.
If the command fails to execute (typically Errno::ENOENT when
it was not found) a SystemCallError exception is raised.
This method modifies process attributes according to given +options+ before
exec(2)
system call. See ::spawn for more details about the
given +options+.
The modified attributes may be retained when exec(2)
system
call fails.
For example, hard resource limits are not restorable.
Consider to create a child process using ::spawn or Kernel#system if this
is not acceptable.
exec "echo *" # echoes list of files in current directory
# never get here
exec "echo", "*" # echoes an asterisk
# never get here
@overload exec([env,] command... [,options]);T;0; @T;!F;"o;#;$T;%i};&i;'@$ ;(I"Xstatic VALUE
f_exec(int c, const VALUE *a, VALUE _)
{
return rb_f_exec(c, a);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#fork;F;[ ;[ ;F;: fork;;K;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @q;'@$ ;*To;;F;
;;;;I"Kernel#exit!;F;[[@c0;[[@]ip;T;:
exit!;0;[ ;{ ;IC;"Exits the process immediately. No exit handlers are
run. status is returned to the underlying system as the
exit status.
Process.exit!(true)
;T;[o;=
;3I"
overload;F;40;;;50;)I"exit!(status=false);T;IC;" ;T;[ ;[ ;I" ;T;0; @z;!F;6i ;>0;[[I"status;TI"
false;T; @z;[ ;I"Exits the process immediately. No exit handlers are
run. status is returned to the underlying system as the
exit status.
Process.exit!(true)
@overload exit!(status=false);T;0; @z;!F;"o;#;$T;%ie;&il;'@$ ;(I"static VALUE
rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
{
int istatus;
if (rb_check_arity(argc, 0, 1) == 1) {
istatus = exit_status_code(argv[0]);
}
else {
istatus = EXIT_FAILURE;
}
_exit(istatus);
UNREACHABLE_RETURN(Qnil);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#system;F;[[@c0;[[@]i;T;:system;0;[ ;{ ;IC;"Executes _command..._ in a subshell.
_command..._ is one of following forms.
[commandline
]
command line string which is passed to the standard shell
[cmdname, arg1, ...
]
command name and one or more arguments (no shell)
[[cmdname, argv0], arg1, ...
]
command name, argv[0]
and zero or more arguments (no shell)
system returns +true+ if the command gives zero exit status,
+false+ for non zero exit status.
Returns +nil+ if command execution fails.
An error status is available in $?
.
If the exception: true
argument is passed, the method
raises an exception instead of returning +false+ or +nil+.
The arguments are processed in the same way as
for Kernel#spawn.
The hash arguments, env and options, are same as #exec and #spawn.
See Kernel#spawn for details.
system("echo *")
system("echo", "*")
produces:
config.h main.rb
*
Error handling:
system("cat nonexistent.txt")
# => false
system("catt nonexistent.txt")
# => nil
system("cat nonexistent.txt", exception: true)
# RuntimeError (Command failed with exit 1: cat)
system("catt nonexistent.txt", exception: true)
# Errno::ENOENT (No such file or directory - catt)
See Kernel#exec for the standard shell.
;T;[o;=
;3I"
overload;F;40;;;50;)I";system([env,] command... [,options], exception: false);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I" true;TI"
false;TI"nil;T; @;[ ;I"@return [true, false, nil];T;0; @;!F;6i ;>0;[[I"[env,][,options];T0[I"exception:;TI"
false;T; @;[ ;I"pExecutes _command..._ in a subshell.
_command..._ is one of following forms.
[commandline
]
command line string which is passed to the standard shell
[cmdname, arg1, ...
]
command name and one or more arguments (no shell)
[[cmdname, argv0], arg1, ...
]
command name, argv[0]
and zero or more arguments (no shell)
system returns +true+ if the command gives zero exit status,
+false+ for non zero exit status.
Returns +nil+ if command execution fails.
An error status is available in $?
.
If the exception: true
argument is passed, the method
raises an exception instead of returning +false+ or +nil+.
The arguments are processed in the same way as
for Kernel#spawn.
The hash arguments, env and options, are same as #exec and #spawn.
See Kernel#spawn for details.
system("echo *")
system("echo", "*")
produces:
config.h main.rb
*
Error handling:
system("cat nonexistent.txt")
# => false
system("catt nonexistent.txt")
# => nil
system("cat nonexistent.txt", exception: true)
# RuntimeError (Command failed with exit 1: cat)
system("catt nonexistent.txt", exception: true)
# Errno::ENOENT (No such file or directory - catt)
See Kernel#exec for the standard shell.
@overload system([env,] command... [,options], exception: false)
@return [true, false, nil];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"istatic VALUE
rb_f_system(int argc, VALUE *argv, VALUE _)
{
/*
* n.b. using alloca for now to simplify future Thread::Light code
* when we need to use malloc for non-native Fiber
*/
struct waitpid_state *w = alloca(sizeof(struct waitpid_state));
rb_pid_t pid; /* may be different from waitpid_state.pid on exec failure */
VALUE execarg_obj;
struct rb_execarg *eargp;
int exec_errnum;
execarg_obj = rb_execarg_new(argc, argv, TRUE, TRUE);
eargp = rb_execarg_get(execarg_obj);
w->ec = GET_EC();
waitpid_state_init(w, 0, 0);
eargp->waitpid_state = w;
pid = rb_execarg_spawn(execarg_obj, 0, 0);
exec_errnum = pid < 0 ? errno : 0;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
if (w->pid > 0) {
/* `pid' (not w->pid) may be < 0 here if execve failed in child */
if (WAITPID_USE_SIGCHLD) {
rb_ensure(waitpid_sleep, (VALUE)w, waitpid_cleanup, (VALUE)w);
}
else {
waitpid_no_SIGCHLD(w);
}
rb_last_status_set(w->status, w->ret);
}
#endif
if (w->pid < 0 /* fork failure */ || pid < 0 /* exec failure */) {
if (eargp->exception) {
int err = exec_errnum ? exec_errnum : w->errnum;
VALUE command = eargp->invoke.sh.shell_script;
RB_GC_GUARD(execarg_obj);
rb_syserr_fail_str(err, command);
}
else {
return Qnil;
}
}
if (w->status == EXIT_SUCCESS) return Qtrue;
if (eargp->exception) {
VALUE command = eargp->invoke.sh.shell_script;
VALUE str = rb_str_new_cstr("Command failed with");
rb_str_cat_cstr(pst_message_status(str, w->status), ": ");
rb_str_append(str, command);
RB_GC_GUARD(execarg_obj);
rb_exc_raise(rb_exc_new_str(rb_eRuntimeError, str));
}
else {
return Qfalse;
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#spawn;F;[[@c0;[[@]i;T;:
spawn;0;[ ;{ ;IC;"7*spawn executes specified command and return its pid.
pid = spawn("tar xf ruby-2.0.0-p195.tar.bz2")
Process.wait pid
pid = spawn(RbConfig.ruby, "-eputs'Hello, world!'")
Process.wait pid
This method is similar to Kernel#system but it doesn't wait for the command
to finish.
The parent process should
use Process.wait to collect
the termination status of its child or
use Process.detach to register
disinterest in their status;
otherwise, the operating system may accumulate zombie processes.
spawn has bunch of options to specify process attributes:
env: hash
name => val : set the environment variable
name => nil : unset the environment variable
the keys and the values except for +nil+ must be strings.
command...:
commandline : command line string which is passed to the standard shell
cmdname, arg1, ... : command name and one or more arguments (This form does not use the shell. See below for caveats.)
[cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
options: hash
clearing environment variables:
:unsetenv_others => true : clear environment variables except specified by env
:unsetenv_others => false : don't clear (default)
process group:
:pgroup => true or 0 : make a new process group
:pgroup => pgid : join the specified process group
:pgroup => nil : don't change the process group (default)
create new process group: Windows only
:new_pgroup => true : the new process is the root process of a new process group
:new_pgroup => false : don't create a new process group (default)
resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
:rlimit_resourcename => limit
:rlimit_resourcename => [cur_limit, max_limit]
umask:
:umask => int
redirection:
key:
FD : single file descriptor in child process
[FD, FD, ...] : multiple file descriptor in child process
value:
FD : redirect to the file descriptor in parent process
string : redirect to file with open(string, "r" or "w")
[string] : redirect to file with open(string, File::RDONLY)
[string, open_mode] : redirect to file with open(string, open_mode, 0644)
[string, open_mode, perm] : redirect to file with open(string, open_mode, perm)
[:child, FD] : redirect to the redirected file descriptor
:close : close the file descriptor in child process
FD is one of follows
:in : the file descriptor 0 which is the standard input
:out : the file descriptor 1 which is the standard output
:err : the file descriptor 2 which is the standard error
integer : the file descriptor of specified the integer
io : the file descriptor specified as io.fileno
file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
:close_others => false : inherit
current directory:
:chdir => str
The cmdname, arg1, ...
form does not use the shell.
However, on different OSes, different things are provided as
built-in commands. An example of this is +'echo'+, which is a
built-in on Windows, but is a normal program on Linux and Mac OS X.
This means that Process.spawn 'echo', '%Path%'
will
display the contents of the %Path% environment variable
on Windows, but Process.spawn 'echo', '$PATH'
prints
the literal $PATH.
If a hash is given as +env+, the environment is
updated by +env+ before exec(2)
in the child process.
If a pair in +env+ has nil as the value, the variable is deleted.
# set FOO as BAR and unset BAZ.
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
If a hash is given as +options+,
it specifies
process group,
create new process group,
resource limit,
current directory,
umask and
redirects for the child process.
Also, it can be specified to clear environment variables.
The :unsetenv_others
key in +options+ specifies
to clear environment variables, other than specified by +env+.
pid = spawn(command, :unsetenv_others=>true) # no environment variable
pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true) # FOO only
The :pgroup
key in +options+ specifies a process group.
The corresponding value should be true, zero, a positive integer, or nil.
true and zero cause the process to be a process leader of a new process group.
A non-zero positive integer causes the process to join the provided process group.
The default value, nil, causes the process to remain in the same process group.
pid = spawn(command, :pgroup=>true) # process leader
pid = spawn(command, :pgroup=>10) # belongs to the process group 10
The :new_pgroup
key in +options+ specifies to pass
+CREATE_NEW_PROCESS_GROUP+ flag to CreateProcessW()
that is
Windows API. This option is only for Windows.
true means the new process is the root process of the new process group.
The new process has CTRL+C disabled. This flag is necessary for
Process.kill(:SIGINT, pid)
on the subprocess.
:new_pgroup is false by default.
pid = spawn(command, :new_pgroup=>true) # new process group
pid = spawn(command, :new_pgroup=>false) # same process group
The :rlimit_
foo key specifies a resource limit.
foo should be one of resource types such as core
.
The corresponding value should be an integer or an array which have one or
two integers: same as cur_limit and max_limit arguments for
Process.setrlimit.
cur, max = Process.getrlimit(:CORE)
pid = spawn(command, :rlimit_core=>[0,max]) # disable core temporary.
pid = spawn(command, :rlimit_core=>max) # enable core dump
pid = spawn(command, :rlimit_core=>0) # never dump core.
The :umask
key in +options+ specifies the umask.
pid = spawn(command, :umask=>077)
The :in, :out, :err, an integer, an IO and an array key specifies a redirection.
The redirection maps a file descriptor in the child process.
For example, stderr can be merged into stdout as follows:
pid = spawn(command, :err=>:out)
pid = spawn(command, 2=>1)
pid = spawn(command, STDERR=>:out)
pid = spawn(command, STDERR=>STDOUT)
The hash keys specifies a file descriptor in the child process
started by #spawn.
:err, 2 and STDERR specifies the standard error stream (stderr).
The hash values specifies a file descriptor in the parent process
which invokes #spawn.
:out, 1 and STDOUT specifies the standard output stream (stdout).
In the above example,
the standard output in the child process is not specified.
So it is inherited from the parent process.
The standard input stream (stdin) can be specified by :in, 0 and STDIN.
A filename can be specified as a hash value.
pid = spawn(command, :in=>"/dev/null") # read mode
pid = spawn(command, :out=>"/dev/null") # write mode
pid = spawn(command, :err=>"log") # write mode
pid = spawn(command, [:out, :err]=>"/dev/null") # write mode
pid = spawn(command, 3=>"/dev/null") # read mode
For stdout and stderr (and combination of them),
it is opened in write mode.
Otherwise read mode is used.
For specifying flags and permission of file creation explicitly,
an array is used instead.
pid = spawn(command, :in=>["file"]) # read mode is assumed
pid = spawn(command, :in=>["file", "r"])
pid = spawn(command, :out=>["log", "w"]) # 0644 assumed
pid = spawn(command, :out=>["log", "w", 0600])
pid = spawn(command, :out=>["log", File::WRONLY|File::EXCL|File::CREAT, 0600])
The array specifies a filename, flags and permission.
The flags can be a string or an integer.
If the flags is omitted or nil, File::RDONLY is assumed.
The permission should be an integer.
If the permission is omitted or nil, 0644 is assumed.
If an array of IOs and integers are specified as a hash key,
all the elements are redirected.
# stdout and stderr is redirected to log file.
# The file "log" is opened just once.
pid = spawn(command, [:out, :err]=>["log", "w"])
Another way to merge multiple file descriptors is [:child, fd].
\[:child, fd] means the file descriptor in the child process.
This is different from fd.
For example, :err=>:out means redirecting child stderr to parent stdout.
But :err=>[:child, :out] means redirecting child stderr to child stdout.
They differ if stdout is redirected in the child process as follows.
# stdout and stderr is redirected to log file.
# The file "log" is opened just once.
pid = spawn(command, :out=>["log", "w"], :err=>[:child, :out])
\[:child, :out] can be used to merge stderr into stdout in IO.popen.
In this case, IO.popen redirects stdout to a pipe in the child process
and [:child, :out] refers the redirected stdout.
io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
p io.read #=> "out\nerr\n"
The :chdir
key in +options+ specifies the current directory.
pid = spawn(command, :chdir=>"/var/tmp")
spawn closes all non-standard unspecified descriptors by default.
The "standard" descriptors are 0, 1 and 2.
This behavior is specified by :close_others option.
:close_others doesn't affect the standard descriptors which are
closed only if :close is specified explicitly.
pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
:close_others is false by default for spawn and IO.popen.
Note that fds which close-on-exec flag is already set are closed
regardless of :close_others option.
So IO.pipe and spawn can be used as IO.popen.
# similar to r = IO.popen(command)
r, w = IO.pipe
pid = spawn(command, :out=>w) # r, w is closed in the child process.
w.close
:close is specified as a hash value to close a fd individually.
f = open(foo)
system(command, f=>:close) # don't inherit f.
If a file descriptor need to be inherited,
io=>io can be used.
# valgrind has --log-fd option for log destination.
# log_w=>log_w indicates log_w.fileno inherits to child process.
log_r, log_w = IO.pipe
pid = spawn("valgrind", "--log-fd=#{log_w.fileno}", "echo", "a", log_w=>log_w)
log_w.close
p log_r.read
It is also possible to exchange file descriptors.
pid = spawn(command, :out=>:err, :err=>:out)
The hash keys specify file descriptors in the child process.
The hash values specifies file descriptors in the parent process.
So the above specifies exchanging stdout and stderr.
Internally, +spawn+ uses an extra file descriptor to resolve such cyclic
file descriptor mapping.
See Kernel.exec for the standard shell.
;T;[o;=
;3I"
overload;F;40;;;50;)I"(spawn([env,] command... [,options]);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"[env,][,options];T0; @o;=
;3I"
overload;F;40;;;50;)I"(spawn([env,] command... [,options]);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"[env,][,options];T0; @;[ ;I"*spawn executes specified command and return its pid.
pid = spawn("tar xf ruby-2.0.0-p195.tar.bz2")
Process.wait pid
pid = spawn(RbConfig.ruby, "-eputs'Hello, world!'")
Process.wait pid
This method is similar to Kernel#system but it doesn't wait for the command
to finish.
The parent process should
use Process.wait to collect
the termination status of its child or
use Process.detach to register
disinterest in their status;
otherwise, the operating system may accumulate zombie processes.
spawn has bunch of options to specify process attributes:
env: hash
name => val : set the environment variable
name => nil : unset the environment variable
the keys and the values except for +nil+ must be strings.
command...:
commandline : command line string which is passed to the standard shell
cmdname, arg1, ... : command name and one or more arguments (This form does not use the shell. See below for caveats.)
[cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
options: hash
clearing environment variables:
:unsetenv_others => true : clear environment variables except specified by env
:unsetenv_others => false : don't clear (default)
process group:
:pgroup => true or 0 : make a new process group
:pgroup => pgid : join the specified process group
:pgroup => nil : don't change the process group (default)
create new process group: Windows only
:new_pgroup => true : the new process is the root process of a new process group
:new_pgroup => false : don't create a new process group (default)
resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
:rlimit_resourcename => limit
:rlimit_resourcename => [cur_limit, max_limit]
umask:
:umask => int
redirection:
key:
FD : single file descriptor in child process
[FD, FD, ...] : multiple file descriptor in child process
value:
FD : redirect to the file descriptor in parent process
string : redirect to file with open(string, "r" or "w")
[string] : redirect to file with open(string, File::RDONLY)
[string, open_mode] : redirect to file with open(string, open_mode, 0644)
[string, open_mode, perm] : redirect to file with open(string, open_mode, perm)
[:child, FD] : redirect to the redirected file descriptor
:close : close the file descriptor in child process
FD is one of follows
:in : the file descriptor 0 which is the standard input
:out : the file descriptor 1 which is the standard output
:err : the file descriptor 2 which is the standard error
integer : the file descriptor of specified the integer
io : the file descriptor specified as io.fileno
file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
:close_others => false : inherit
current directory:
:chdir => str
The cmdname, arg1, ...
form does not use the shell.
However, on different OSes, different things are provided as
built-in commands. An example of this is +'echo'+, which is a
built-in on Windows, but is a normal program on Linux and Mac OS X.
This means that Process.spawn 'echo', '%Path%'
will
display the contents of the %Path% environment variable
on Windows, but Process.spawn 'echo', '$PATH'
prints
the literal $PATH.
If a hash is given as +env+, the environment is
updated by +env+ before exec(2)
in the child process.
If a pair in +env+ has nil as the value, the variable is deleted.
# set FOO as BAR and unset BAZ.
pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
If a hash is given as +options+,
it specifies
process group,
create new process group,
resource limit,
current directory,
umask and
redirects for the child process.
Also, it can be specified to clear environment variables.
The :unsetenv_others
key in +options+ specifies
to clear environment variables, other than specified by +env+.
pid = spawn(command, :unsetenv_others=>true) # no environment variable
pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true) # FOO only
The :pgroup
key in +options+ specifies a process group.
The corresponding value should be true, zero, a positive integer, or nil.
true and zero cause the process to be a process leader of a new process group.
A non-zero positive integer causes the process to join the provided process group.
The default value, nil, causes the process to remain in the same process group.
pid = spawn(command, :pgroup=>true) # process leader
pid = spawn(command, :pgroup=>10) # belongs to the process group 10
The :new_pgroup
key in +options+ specifies to pass
+CREATE_NEW_PROCESS_GROUP+ flag to CreateProcessW()
that is
Windows API. This option is only for Windows.
true means the new process is the root process of the new process group.
The new process has CTRL+C disabled. This flag is necessary for
Process.kill(:SIGINT, pid)
on the subprocess.
:new_pgroup is false by default.
pid = spawn(command, :new_pgroup=>true) # new process group
pid = spawn(command, :new_pgroup=>false) # same process group
The :rlimit_
foo key specifies a resource limit.
foo should be one of resource types such as core
.
The corresponding value should be an integer or an array which have one or
two integers: same as cur_limit and max_limit arguments for
Process.setrlimit.
cur, max = Process.getrlimit(:CORE)
pid = spawn(command, :rlimit_core=>[0,max]) # disable core temporary.
pid = spawn(command, :rlimit_core=>max) # enable core dump
pid = spawn(command, :rlimit_core=>0) # never dump core.
The :umask
key in +options+ specifies the umask.
pid = spawn(command, :umask=>077)
The :in, :out, :err, an integer, an IO and an array key specifies a redirection.
The redirection maps a file descriptor in the child process.
For example, stderr can be merged into stdout as follows:
pid = spawn(command, :err=>:out)
pid = spawn(command, 2=>1)
pid = spawn(command, STDERR=>:out)
pid = spawn(command, STDERR=>STDOUT)
The hash keys specifies a file descriptor in the child process
started by #spawn.
:err, 2 and STDERR specifies the standard error stream (stderr).
The hash values specifies a file descriptor in the parent process
which invokes #spawn.
:out, 1 and STDOUT specifies the standard output stream (stdout).
In the above example,
the standard output in the child process is not specified.
So it is inherited from the parent process.
The standard input stream (stdin) can be specified by :in, 0 and STDIN.
A filename can be specified as a hash value.
pid = spawn(command, :in=>"/dev/null") # read mode
pid = spawn(command, :out=>"/dev/null") # write mode
pid = spawn(command, :err=>"log") # write mode
pid = spawn(command, [:out, :err]=>"/dev/null") # write mode
pid = spawn(command, 3=>"/dev/null") # read mode
For stdout and stderr (and combination of them),
it is opened in write mode.
Otherwise read mode is used.
For specifying flags and permission of file creation explicitly,
an array is used instead.
pid = spawn(command, :in=>["file"]) # read mode is assumed
pid = spawn(command, :in=>["file", "r"])
pid = spawn(command, :out=>["log", "w"]) # 0644 assumed
pid = spawn(command, :out=>["log", "w", 0600])
pid = spawn(command, :out=>["log", File::WRONLY|File::EXCL|File::CREAT, 0600])
The array specifies a filename, flags and permission.
The flags can be a string or an integer.
If the flags is omitted or nil, File::RDONLY is assumed.
The permission should be an integer.
If the permission is omitted or nil, 0644 is assumed.
If an array of IOs and integers are specified as a hash key,
all the elements are redirected.
# stdout and stderr is redirected to log file.
# The file "log" is opened just once.
pid = spawn(command, [:out, :err]=>["log", "w"])
Another way to merge multiple file descriptors is [:child, fd].
\[:child, fd] means the file descriptor in the child process.
This is different from fd.
For example, :err=>:out means redirecting child stderr to parent stdout.
But :err=>[:child, :out] means redirecting child stderr to child stdout.
They differ if stdout is redirected in the child process as follows.
# stdout and stderr is redirected to log file.
# The file "log" is opened just once.
pid = spawn(command, :out=>["log", "w"], :err=>[:child, :out])
\[:child, :out] can be used to merge stderr into stdout in IO.popen.
In this case, IO.popen redirects stdout to a pipe in the child process
and [:child, :out] refers the redirected stdout.
io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
p io.read #=> "out\nerr\n"
The :chdir
key in +options+ specifies the current directory.
pid = spawn(command, :chdir=>"/var/tmp")
spawn closes all non-standard unspecified descriptors by default.
The "standard" descriptors are 0, 1 and 2.
This behavior is specified by :close_others option.
:close_others doesn't affect the standard descriptors which are
closed only if :close is specified explicitly.
pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
:close_others is false by default for spawn and IO.popen.
Note that fds which close-on-exec flag is already set are closed
regardless of :close_others option.
So IO.pipe and spawn can be used as IO.popen.
# similar to r = IO.popen(command)
r, w = IO.pipe
pid = spawn(command, :out=>w) # r, w is closed in the child process.
w.close
:close is specified as a hash value to close a fd individually.
f = open(foo)
system(command, f=>:close) # don't inherit f.
If a file descriptor need to be inherited,
io=>io can be used.
# valgrind has --log-fd option for log destination.
# log_w=>log_w indicates log_w.fileno inherits to child process.
log_r, log_w = IO.pipe
pid = spawn("valgrind", "--log-fd=#{log_w.fileno}", "echo", "a", log_w=>log_w)
log_w.close
p log_r.read
It is also possible to exchange file descriptors.
pid = spawn(command, :out=>:err, :err=>:out)
The hash keys specify file descriptors in the child process.
The hash values specifies file descriptors in the parent process.
So the above specifies exchanging stdout and stderr.
Internally, +spawn+ uses an extra file descriptor to resolve such cyclic
file descriptor mapping.
See Kernel.exec for the standard shell.
@overload spawn([env,] command... [,options])
@overload spawn([env,] command... [,options]);T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_spawn(int argc, VALUE *argv, VALUE _)
{
rb_pid_t pid;
char errmsg[CHILD_ERRMSG_BUFLEN] = { '\0' };
VALUE execarg_obj, fail_str;
struct rb_execarg *eargp;
execarg_obj = rb_execarg_new(argc, argv, TRUE, FALSE);
eargp = rb_execarg_get(execarg_obj);
fail_str = eargp->use_shell ? eargp->invoke.sh.shell_script : eargp->invoke.cmd.command_name;
pid = rb_execarg_spawn(execarg_obj, errmsg, sizeof(errmsg));
if (pid == -1) {
int err = errno;
rb_exec_fail(eargp, err, errmsg);
RB_GC_GUARD(execarg_obj);
rb_syserr_fail_str(err, fail_str);
}
#if defined(HAVE_WORKING_FORK) || defined(HAVE_SPAWNV)
return PIDT2NUM(pid);
#else
return Qnil;
#endif
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#sleep;F;[[@c0;[[@]i';T;:
sleep;0;[ ;{ ;IC;"Suspends the current thread for _duration_ seconds (which may be any number,
including a +Float+ with fractional seconds). Returns the actual number of
seconds slept (rounded), which may be less than that asked for if another
thread calls Thread#run. Called without an argument, sleep()
will sleep forever.
Time.new #=> 2008-03-08 19:56:19 +0900
sleep 1.2 #=> 1
Time.new #=> 2008-03-08 19:56:20 +0900
sleep 1.9 #=> 2
Time.new #=> 2008-03-08 19:56:22 +0900
;T;[o;=
;3I"
overload;F;40;;;50;)I"sleep([duration]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Integer;T; @;[ ;I"@return [Integer];T;0; @;!F;6i ;>0;[[I"[duration];T0; @;[ ;I"Suspends the current thread for _duration_ seconds (which may be any number,
including a +Float+ with fractional seconds). Returns the actual number of
seconds slept (rounded), which may be less than that asked for if another
thread calls Thread#run. Called without an argument, sleep()
will sleep forever.
Time.new #=> 2008-03-08 19:56:19 +0900
sleep 1.2 #=> 1
Time.new #=> 2008-03-08 19:56:20 +0900
sleep 1.9 #=> 2
Time.new #=> 2008-03-08 19:56:22 +0900
@overload sleep([duration])
@return [Integer];T;0; @;!F;"o;#;$T;%i;&i$;'@$ ;(I"-static VALUE
rb_f_sleep(int argc, VALUE *argv, VALUE _)
{
time_t beg, end;
beg = time(0);
if (argc == 0) {
rb_thread_sleep_forever();
}
else {
rb_check_arity(argc, 0, 1);
rb_thread_wait_for(rb_time_interval(argv[0]));
}
end = time(0) - beg;
return INT2FIX(end);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#exit;F;[[I"*a;T0[I"_;T0;[[@]i;T;: exit;0;[ ;{ ;IC;"Initiates the termination of the Ruby script by raising the
SystemExit exception. This exception may be caught. The
optional parameter is used to return a status code to the invoking
environment.
+true+ and +FALSE+ of _status_ means success and failure
respectively. The interpretation of other integer values are
system dependent.
begin
exit
puts "never get here"
rescue SystemExit
puts "rescued a SystemExit exception"
end
puts "after begin block"
produces:
rescued a SystemExit exception
after begin block
Just prior to termination, Ruby executes any at_exit
functions (see Kernel::at_exit) and runs any object finalizers
(see ObjectSpace::define_finalizer).
at_exit { puts "at_exit function" }
ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
exit
produces:
at_exit function
in finalizer
;T;[o;=
;3I"
overload;F;40;;;50;)I"exit(status=true);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"status;TI" true;T; @o;=
;3I"
overload;F;40;:Kernel::exit;50;)I"Kernel::exit(status=true);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"status;TI" true;T; @o;=
;3I"
overload;F;40;:Process::exit;50;)I"Process::exit(status=true);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"status;TI" true;T; @;[ ;I"Initiates the termination of the Ruby script by raising the
SystemExit exception. This exception may be caught. The
optional parameter is used to return a status code to the invoking
environment.
+true+ and +FALSE+ of _status_ means success and failure
respectively. The interpretation of other integer values are
system dependent.
begin
exit
puts "never get here"
rescue SystemExit
puts "rescued a SystemExit exception"
end
puts "after begin block"
produces:
rescued a SystemExit exception
after begin block
Just prior to termination, Ruby executes any at_exit
functions (see Kernel::at_exit) and runs any object finalizers
(see ObjectSpace::define_finalizer).
at_exit { puts "at_exit function" }
ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
exit
produces:
at_exit function
in finalizer
@overload exit(status=true)
@overload Kernel::exit(status=true)
@overload Process::exit(status=true);T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"Xstatic VALUE
f_exit(int c, const VALUE *a, VALUE _)
{
return rb_f_exit(c, a);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#abort;F;[[I"*a;T0[I"_;T0;[[@]i;T;:
abort;0;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @+;'@$ ;(I"Zstatic VALUE
f_abort(int c, const VALUE *a, VALUE _)
{
return rb_f_abort(c, a);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#sprintf;F;[[I"*v;T0[I"_;T0;[[@i;T;:sprintf;0;[ ;{ ;IC;"F,Returns the string resulting from applying format_string to
any additional arguments. Within the format string, any characters
other than format sequences are copied to the result.
The syntax of a format sequence is as follows.
%[flags][width][.precision]type
A format
sequence consists of a percent sign, followed by optional flags,
width, and precision indicators, then terminated with a field type
character. The field type controls how the corresponding
sprintf
argument is to be interpreted, while the flags
modify that interpretation.
The field type characters are:
Field | Integer Format
------+--------------------------------------------------------------
b | Convert argument as a binary number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..1'.
B | Equivalent to `b', but uses an uppercase 0B for prefix
| in the alternative format by #.
d | Convert argument as a decimal number.
i | Identical to `d'.
o | Convert argument as an octal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..7'.
u | Identical to `d'.
x | Convert argument as a hexadecimal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..f' (representing an infinite string of
| leading 'ff's).
X | Equivalent to `x', but uses uppercase letters.
Field | Float Format
------+--------------------------------------------------------------
e | Convert floating point argument into exponential notation
| with one digit before the decimal point as [-]d.dddddde[+-]dd.
| The precision specifies the number of digits after the decimal
| point (defaulting to six).
E | Equivalent to `e', but uses an uppercase E to indicate
| the exponent.
f | Convert floating point argument as [-]ddd.dddddd,
| where the precision specifies the number of digits after
| the decimal point.
g | Convert a floating point number using exponential form
| if the exponent is less than -4 or greater than or
| equal to the precision, or in dd.dddd form otherwise.
| The precision specifies the number of significant digits.
G | Equivalent to `g', but use an uppercase `E' in exponent form.
a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
| which is consisted from optional sign, "0x", fraction part
| as hexadecimal, "p", and exponential part as decimal.
A | Equivalent to `a', but use uppercase `X' and `P'.
Field | Other Format
------+--------------------------------------------------------------
c | Argument is the numeric code for a single character or
| a single character string itself.
p | The valuing of argument.inspect.
s | Argument is a string to be substituted. If the format
| sequence contains a precision, at most that many characters
| will be copied.
% | A percent sign itself will be displayed. No argument taken.
The flags modifies the behavior of the formats.
The flag characters are:
Flag | Applies to | Meaning
---------+---------------+-----------------------------------------
space | bBdiouxX | Leave a space at the start of
| aAeEfgG | non-negative numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
(digit)$ | all | Specifies the absolute argument number
| | for this field. Absolute and relative
| | argument numbers cannot be mixed in a
| | sprintf string.
---------+---------------+-----------------------------------------
# | bBoxX | Use an alternative format.
| aAeEfgG | For the conversions `o', increase the precision
| | until the first digit will be `0' if
| | it is not formatted as complements.
| | For the conversions `x', `X', `b' and `B'
| | on non-zero, prefix the result with ``0x'',
| | ``0X'', ``0b'' and ``0B'', respectively.
| | For `a', `A', `e', `E', `f', `g', and 'G',
| | force a decimal point to be added,
| | even if no digits follow.
| | For `g' and 'G', do not remove trailing zeros.
---------+---------------+-----------------------------------------
+ | bBdiouxX | Add a leading plus sign to non-negative
| aAeEfgG | numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
- | all | Left-justify the result of this conversion.
---------+---------------+-----------------------------------------
0 (zero) | bBdiouxX | Pad with zeros, not spaces.
| aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
| (numeric fmt) | is used for negative numbers formatted as
| | complements.
---------+---------------+-----------------------------------------
* | all | Use the next argument as the field width.
| | If negative, left-justify the result. If the
| | asterisk is followed by a number and a dollar
| | sign, use the indicated argument as the width.
Examples of flags:
# `+' and space flag specifies the sign of non-negative numbers.
sprintf("%d", 123) #=> "123"
sprintf("%+d", 123) #=> "+123"
sprintf("% d", 123) #=> " 123"
# `#' flag for `o' increases number of digits to show `0'.
# `+' and space flag changes format of negative numbers.
sprintf("%o", 123) #=> "173"
sprintf("%#o", 123) #=> "0173"
sprintf("%+o", -123) #=> "-173"
sprintf("%o", -123) #=> "..7605"
sprintf("%#o", -123) #=> "..7605"
# `#' flag for `x' add a prefix `0x' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%x", 123) #=> "7b"
sprintf("%#x", 123) #=> "0x7b"
sprintf("%+x", -123) #=> "-7b"
sprintf("%x", -123) #=> "..f85"
sprintf("%#x", -123) #=> "0x..f85"
sprintf("%#x", 0) #=> "0"
# `#' for `X' uses the prefix `0X'.
sprintf("%X", 123) #=> "7B"
sprintf("%#X", 123) #=> "0X7B"
# `#' flag for `b' add a prefix `0b' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%b", 123) #=> "1111011"
sprintf("%#b", 123) #=> "0b1111011"
sprintf("%+b", -123) #=> "-1111011"
sprintf("%b", -123) #=> "..10000101"
sprintf("%#b", -123) #=> "0b..10000101"
sprintf("%#b", 0) #=> "0"
# `#' for `B' uses the prefix `0B'.
sprintf("%B", 123) #=> "1111011"
sprintf("%#B", 123) #=> "0B1111011"
# `#' for `e' forces to show the decimal point.
sprintf("%.0e", 1) #=> "1e+00"
sprintf("%#.0e", 1) #=> "1.e+00"
# `#' for `f' forces to show the decimal point.
sprintf("%.0f", 1234) #=> "1234"
sprintf("%#.0f", 1234) #=> "1234."
# `#' for `g' forces to show the decimal point.
# It also disables stripping lowest zeros.
sprintf("%g", 123.4) #=> "123.4"
sprintf("%#g", 123.4) #=> "123.400"
sprintf("%g", 123456) #=> "123456"
sprintf("%#g", 123456) #=> "123456."
The field width is an optional integer, followed optionally by a
period and a precision. The width specifies the minimum number of
characters that will be written to the result for this field.
Examples of width:
# padding is done by spaces, width=20
# 0 or radix-1. <------------------>
sprintf("%20d", 123) #=> " 123"
sprintf("%+20d", 123) #=> " +123"
sprintf("%020d", 123) #=> "00000000000000000123"
sprintf("%+020d", 123) #=> "+0000000000000000123"
sprintf("% 020d", 123) #=> " 0000000000000000123"
sprintf("%-20d", 123) #=> "123 "
sprintf("%-+20d", 123) #=> "+123 "
sprintf("%- 20d", 123) #=> " 123 "
sprintf("%020x", -123) #=> "..ffffffffffffffff85"
For
numeric fields, the precision controls the number of decimal places
displayed. For string fields, the precision determines the maximum
number of characters to be copied from the string. (Thus, the format
sequence %10.10s
will always contribute exactly ten
characters to the result.)
Examples of precisions:
# precision for `d', 'o', 'x' and 'b' is
# minimum number of digits <------>
sprintf("%20.8d", 123) #=> " 00000123"
sprintf("%20.8o", 123) #=> " 00000173"
sprintf("%20.8x", 123) #=> " 0000007b"
sprintf("%20.8b", 123) #=> " 01111011"
sprintf("%20.8d", -123) #=> " -00000123"
sprintf("%20.8o", -123) #=> " ..777605"
sprintf("%20.8x", -123) #=> " ..ffff85"
sprintf("%20.8b", -11) #=> " ..110101"
# "0x" and "0b" for `#x' and `#b' is not counted for
# precision but "0" for `#o' is counted. <------>
sprintf("%#20.8d", 123) #=> " 00000123"
sprintf("%#20.8o", 123) #=> " 00000173"
sprintf("%#20.8x", 123) #=> " 0x0000007b"
sprintf("%#20.8b", 123) #=> " 0b01111011"
sprintf("%#20.8d", -123) #=> " -00000123"
sprintf("%#20.8o", -123) #=> " ..777605"
sprintf("%#20.8x", -123) #=> " 0x..ffff85"
sprintf("%#20.8b", -11) #=> " 0b..110101"
# precision for `e' is number of
# digits after the decimal point <------>
sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
# precision for `f' is number of
# digits after the decimal point <------>
sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
# precision for `g' is number of
# significant digits <------->
sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
# <------->
sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
# precision for `s' is
# maximum number of characters <------>
sprintf("%20.8s", "string test") #=> " string t"
Examples:
sprintf("%d %04x", 123, 123) #=> "123 007b"
sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
sprintf("%u", -123) #=> "-123"
For more complex formatting, Ruby supports a reference by name.
%s style uses format style, but %{name} style doesn't.
Examples:
sprintf("%d : %f", { :foo => 1, :bar => 2 })
#=> 1 : 2.000000
sprintf("%{foo}f", { :foo => 1 })
# => "1f"
;T;[o;=
;3I"
overload;F;40;:format;50;)I",format(format_string [, arguments...] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;;[ ;I"@return [String];T;0; @;;!F;6i ;>0;[[I""format_string[, arguments...];T0; @;o;=
;3I"
overload;F;40;;;50;)I"-sprintf(format_string [, arguments...] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;;[ ;I"@return [String];T;0; @;;!F;6i ;>0;[[I""format_string[, arguments...];T0; @;;[ ;I",Returns the string resulting from applying format_string to
any additional arguments. Within the format string, any characters
other than format sequences are copied to the result.
The syntax of a format sequence is as follows.
%[flags][width][.precision]type
A format
sequence consists of a percent sign, followed by optional flags,
width, and precision indicators, then terminated with a field type
character. The field type controls how the corresponding
sprintf
argument is to be interpreted, while the flags
modify that interpretation.
The field type characters are:
Field | Integer Format
------+--------------------------------------------------------------
b | Convert argument as a binary number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..1'.
B | Equivalent to `b', but uses an uppercase 0B for prefix
| in the alternative format by #.
d | Convert argument as a decimal number.
i | Identical to `d'.
o | Convert argument as an octal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..7'.
u | Identical to `d'.
x | Convert argument as a hexadecimal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..f' (representing an infinite string of
| leading 'ff's).
X | Equivalent to `x', but uses uppercase letters.
Field | Float Format
------+--------------------------------------------------------------
e | Convert floating point argument into exponential notation
| with one digit before the decimal point as [-]d.dddddde[+-]dd.
| The precision specifies the number of digits after the decimal
| point (defaulting to six).
E | Equivalent to `e', but uses an uppercase E to indicate
| the exponent.
f | Convert floating point argument as [-]ddd.dddddd,
| where the precision specifies the number of digits after
| the decimal point.
g | Convert a floating point number using exponential form
| if the exponent is less than -4 or greater than or
| equal to the precision, or in dd.dddd form otherwise.
| The precision specifies the number of significant digits.
G | Equivalent to `g', but use an uppercase `E' in exponent form.
a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
| which is consisted from optional sign, "0x", fraction part
| as hexadecimal, "p", and exponential part as decimal.
A | Equivalent to `a', but use uppercase `X' and `P'.
Field | Other Format
------+--------------------------------------------------------------
c | Argument is the numeric code for a single character or
| a single character string itself.
p | The valuing of argument.inspect.
s | Argument is a string to be substituted. If the format
| sequence contains a precision, at most that many characters
| will be copied.
% | A percent sign itself will be displayed. No argument taken.
The flags modifies the behavior of the formats.
The flag characters are:
Flag | Applies to | Meaning
---------+---------------+-----------------------------------------
space | bBdiouxX | Leave a space at the start of
| aAeEfgG | non-negative numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
(digit)$ | all | Specifies the absolute argument number
| | for this field. Absolute and relative
| | argument numbers cannot be mixed in a
| | sprintf string.
---------+---------------+-----------------------------------------
# | bBoxX | Use an alternative format.
| aAeEfgG | For the conversions `o', increase the precision
| | until the first digit will be `0' if
| | it is not formatted as complements.
| | For the conversions `x', `X', `b' and `B'
| | on non-zero, prefix the result with ``0x'',
| | ``0X'', ``0b'' and ``0B'', respectively.
| | For `a', `A', `e', `E', `f', `g', and 'G',
| | force a decimal point to be added,
| | even if no digits follow.
| | For `g' and 'G', do not remove trailing zeros.
---------+---------------+-----------------------------------------
+ | bBdiouxX | Add a leading plus sign to non-negative
| aAeEfgG | numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
- | all | Left-justify the result of this conversion.
---------+---------------+-----------------------------------------
0 (zero) | bBdiouxX | Pad with zeros, not spaces.
| aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
| (numeric fmt) | is used for negative numbers formatted as
| | complements.
---------+---------------+-----------------------------------------
* | all | Use the next argument as the field width.
| | If negative, left-justify the result. If the
| | asterisk is followed by a number and a dollar
| | sign, use the indicated argument as the width.
Examples of flags:
# `+' and space flag specifies the sign of non-negative numbers.
sprintf("%d", 123) #=> "123"
sprintf("%+d", 123) #=> "+123"
sprintf("% d", 123) #=> " 123"
# `#' flag for `o' increases number of digits to show `0'.
# `+' and space flag changes format of negative numbers.
sprintf("%o", 123) #=> "173"
sprintf("%#o", 123) #=> "0173"
sprintf("%+o", -123) #=> "-173"
sprintf("%o", -123) #=> "..7605"
sprintf("%#o", -123) #=> "..7605"
# `#' flag for `x' add a prefix `0x' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%x", 123) #=> "7b"
sprintf("%#x", 123) #=> "0x7b"
sprintf("%+x", -123) #=> "-7b"
sprintf("%x", -123) #=> "..f85"
sprintf("%#x", -123) #=> "0x..f85"
sprintf("%#x", 0) #=> "0"
# `#' for `X' uses the prefix `0X'.
sprintf("%X", 123) #=> "7B"
sprintf("%#X", 123) #=> "0X7B"
# `#' flag for `b' add a prefix `0b' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%b", 123) #=> "1111011"
sprintf("%#b", 123) #=> "0b1111011"
sprintf("%+b", -123) #=> "-1111011"
sprintf("%b", -123) #=> "..10000101"
sprintf("%#b", -123) #=> "0b..10000101"
sprintf("%#b", 0) #=> "0"
# `#' for `B' uses the prefix `0B'.
sprintf("%B", 123) #=> "1111011"
sprintf("%#B", 123) #=> "0B1111011"
# `#' for `e' forces to show the decimal point.
sprintf("%.0e", 1) #=> "1e+00"
sprintf("%#.0e", 1) #=> "1.e+00"
# `#' for `f' forces to show the decimal point.
sprintf("%.0f", 1234) #=> "1234"
sprintf("%#.0f", 1234) #=> "1234."
# `#' for `g' forces to show the decimal point.
# It also disables stripping lowest zeros.
sprintf("%g", 123.4) #=> "123.4"
sprintf("%#g", 123.4) #=> "123.400"
sprintf("%g", 123456) #=> "123456"
sprintf("%#g", 123456) #=> "123456."
The field width is an optional integer, followed optionally by a
period and a precision. The width specifies the minimum number of
characters that will be written to the result for this field.
Examples of width:
# padding is done by spaces, width=20
# 0 or radix-1. <------------------>
sprintf("%20d", 123) #=> " 123"
sprintf("%+20d", 123) #=> " +123"
sprintf("%020d", 123) #=> "00000000000000000123"
sprintf("%+020d", 123) #=> "+0000000000000000123"
sprintf("% 020d", 123) #=> " 0000000000000000123"
sprintf("%-20d", 123) #=> "123 "
sprintf("%-+20d", 123) #=> "+123 "
sprintf("%- 20d", 123) #=> " 123 "
sprintf("%020x", -123) #=> "..ffffffffffffffff85"
For
numeric fields, the precision controls the number of decimal places
displayed. For string fields, the precision determines the maximum
number of characters to be copied from the string. (Thus, the format
sequence %10.10s
will always contribute exactly ten
characters to the result.)
Examples of precisions:
# precision for `d', 'o', 'x' and 'b' is
# minimum number of digits <------>
sprintf("%20.8d", 123) #=> " 00000123"
sprintf("%20.8o", 123) #=> " 00000173"
sprintf("%20.8x", 123) #=> " 0000007b"
sprintf("%20.8b", 123) #=> " 01111011"
sprintf("%20.8d", -123) #=> " -00000123"
sprintf("%20.8o", -123) #=> " ..777605"
sprintf("%20.8x", -123) #=> " ..ffff85"
sprintf("%20.8b", -11) #=> " ..110101"
# "0x" and "0b" for `#x' and `#b' is not counted for
# precision but "0" for `#o' is counted. <------>
sprintf("%#20.8d", 123) #=> " 00000123"
sprintf("%#20.8o", 123) #=> " 00000173"
sprintf("%#20.8x", 123) #=> " 0x0000007b"
sprintf("%#20.8b", 123) #=> " 0b01111011"
sprintf("%#20.8d", -123) #=> " -00000123"
sprintf("%#20.8o", -123) #=> " ..777605"
sprintf("%#20.8x", -123) #=> " 0x..ffff85"
sprintf("%#20.8b", -11) #=> " 0b..110101"
# precision for `e' is number of
# digits after the decimal point <------>
sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
# precision for `f' is number of
# digits after the decimal point <------>
sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
# precision for `g' is number of
# significant digits <------->
sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
# <------->
sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
# precision for `s' is
# maximum number of characters <------>
sprintf("%20.8s", "string test") #=> " string t"
Examples:
sprintf("%d %04x", 123, 123) #=> "123 007b"
sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
sprintf("%u", -123) #=> "-123"
For more complex formatting, Ruby supports a reference by name.
%s style uses format style, but %{name} style doesn't.
Examples:
sprintf("%d : %f", { :foo => 1, :bar => 2 })
#=> 1 : 2.000000
sprintf("%{foo}f", { :foo => 1 })
# => "1f"
@overload format(format_string [, arguments...] )
@return [String]
@overload sprintf(format_string [, arguments...] )
@return [String];T;0; @;;!F;"o;#;$T;%i;&i;'@$ ;(I"^static VALUE
f_sprintf(int c, const VALUE *v, VALUE _)
{
return rb_f_sprintf(c, v);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#format;F;[[I"*v;T0[I"_;T0;[[@i;T;;;0;[ ;{ ;IC;"F,Returns the string resulting from applying format_string to
any additional arguments. Within the format string, any characters
other than format sequences are copied to the result.
The syntax of a format sequence is as follows.
%[flags][width][.precision]type
A format
sequence consists of a percent sign, followed by optional flags,
width, and precision indicators, then terminated with a field type
character. The field type controls how the corresponding
sprintf
argument is to be interpreted, while the flags
modify that interpretation.
The field type characters are:
Field | Integer Format
------+--------------------------------------------------------------
b | Convert argument as a binary number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..1'.
B | Equivalent to `b', but uses an uppercase 0B for prefix
| in the alternative format by #.
d | Convert argument as a decimal number.
i | Identical to `d'.
o | Convert argument as an octal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..7'.
u | Identical to `d'.
x | Convert argument as a hexadecimal number.
| Negative numbers will be displayed as a two's complement
| prefixed with `..f' (representing an infinite string of
| leading 'ff's).
X | Equivalent to `x', but uses uppercase letters.
Field | Float Format
------+--------------------------------------------------------------
e | Convert floating point argument into exponential notation
| with one digit before the decimal point as [-]d.dddddde[+-]dd.
| The precision specifies the number of digits after the decimal
| point (defaulting to six).
E | Equivalent to `e', but uses an uppercase E to indicate
| the exponent.
f | Convert floating point argument as [-]ddd.dddddd,
| where the precision specifies the number of digits after
| the decimal point.
g | Convert a floating point number using exponential form
| if the exponent is less than -4 or greater than or
| equal to the precision, or in dd.dddd form otherwise.
| The precision specifies the number of significant digits.
G | Equivalent to `g', but use an uppercase `E' in exponent form.
a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
| which is consisted from optional sign, "0x", fraction part
| as hexadecimal, "p", and exponential part as decimal.
A | Equivalent to `a', but use uppercase `X' and `P'.
Field | Other Format
------+--------------------------------------------------------------
c | Argument is the numeric code for a single character or
| a single character string itself.
p | The valuing of argument.inspect.
s | Argument is a string to be substituted. If the format
| sequence contains a precision, at most that many characters
| will be copied.
% | A percent sign itself will be displayed. No argument taken.
The flags modifies the behavior of the formats.
The flag characters are:
Flag | Applies to | Meaning
---------+---------------+-----------------------------------------
space | bBdiouxX | Leave a space at the start of
| aAeEfgG | non-negative numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
(digit)$ | all | Specifies the absolute argument number
| | for this field. Absolute and relative
| | argument numbers cannot be mixed in a
| | sprintf string.
---------+---------------+-----------------------------------------
# | bBoxX | Use an alternative format.
| aAeEfgG | For the conversions `o', increase the precision
| | until the first digit will be `0' if
| | it is not formatted as complements.
| | For the conversions `x', `X', `b' and `B'
| | on non-zero, prefix the result with ``0x'',
| | ``0X'', ``0b'' and ``0B'', respectively.
| | For `a', `A', `e', `E', `f', `g', and 'G',
| | force a decimal point to be added,
| | even if no digits follow.
| | For `g' and 'G', do not remove trailing zeros.
---------+---------------+-----------------------------------------
+ | bBdiouxX | Add a leading plus sign to non-negative
| aAeEfgG | numbers.
| (numeric fmt) | For `o', `x', `X', `b' and `B', use
| | a minus sign with absolute value for
| | negative values.
---------+---------------+-----------------------------------------
- | all | Left-justify the result of this conversion.
---------+---------------+-----------------------------------------
0 (zero) | bBdiouxX | Pad with zeros, not spaces.
| aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
| (numeric fmt) | is used for negative numbers formatted as
| | complements.
---------+---------------+-----------------------------------------
* | all | Use the next argument as the field width.
| | If negative, left-justify the result. If the
| | asterisk is followed by a number and a dollar
| | sign, use the indicated argument as the width.
Examples of flags:
# `+' and space flag specifies the sign of non-negative numbers.
sprintf("%d", 123) #=> "123"
sprintf("%+d", 123) #=> "+123"
sprintf("% d", 123) #=> " 123"
# `#' flag for `o' increases number of digits to show `0'.
# `+' and space flag changes format of negative numbers.
sprintf("%o", 123) #=> "173"
sprintf("%#o", 123) #=> "0173"
sprintf("%+o", -123) #=> "-173"
sprintf("%o", -123) #=> "..7605"
sprintf("%#o", -123) #=> "..7605"
# `#' flag for `x' add a prefix `0x' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%x", 123) #=> "7b"
sprintf("%#x", 123) #=> "0x7b"
sprintf("%+x", -123) #=> "-7b"
sprintf("%x", -123) #=> "..f85"
sprintf("%#x", -123) #=> "0x..f85"
sprintf("%#x", 0) #=> "0"
# `#' for `X' uses the prefix `0X'.
sprintf("%X", 123) #=> "7B"
sprintf("%#X", 123) #=> "0X7B"
# `#' flag for `b' add a prefix `0b' for non-zero numbers.
# `+' and space flag disables complements for negative numbers.
sprintf("%b", 123) #=> "1111011"
sprintf("%#b", 123) #=> "0b1111011"
sprintf("%+b", -123) #=> "-1111011"
sprintf("%b", -123) #=> "..10000101"
sprintf("%#b", -123) #=> "0b..10000101"
sprintf("%#b", 0) #=> "0"
# `#' for `B' uses the prefix `0B'.
sprintf("%B", 123) #=> "1111011"
sprintf("%#B", 123) #=> "0B1111011"
# `#' for `e' forces to show the decimal point.
sprintf("%.0e", 1) #=> "1e+00"
sprintf("%#.0e", 1) #=> "1.e+00"
# `#' for `f' forces to show the decimal point.
sprintf("%.0f", 1234) #=> "1234"
sprintf("%#.0f", 1234) #=> "1234."
# `#' for `g' forces to show the decimal point.
# It also disables stripping lowest zeros.
sprintf("%g", 123.4) #=> "123.4"
sprintf("%#g", 123.4) #=> "123.400"
sprintf("%g", 123456) #=> "123456"
sprintf("%#g", 123456) #=> "123456."
The field width is an optional integer, followed optionally by a
period and a precision. The width specifies the minimum number of
characters that will be written to the result for this field.
Examples of width:
# padding is done by spaces, width=20
# 0 or radix-1. <------------------>
sprintf("%20d", 123) #=> " 123"
sprintf("%+20d", 123) #=> " +123"
sprintf("%020d", 123) #=> "00000000000000000123"
sprintf("%+020d", 123) #=> "+0000000000000000123"
sprintf("% 020d", 123) #=> " 0000000000000000123"
sprintf("%-20d", 123) #=> "123 "
sprintf("%-+20d", 123) #=> "+123 "
sprintf("%- 20d", 123) #=> " 123 "
sprintf("%020x", -123) #=> "..ffffffffffffffff85"
For
numeric fields, the precision controls the number of decimal places
displayed. For string fields, the precision determines the maximum
number of characters to be copied from the string. (Thus, the format
sequence %10.10s
will always contribute exactly ten
characters to the result.)
Examples of precisions:
# precision for `d', 'o', 'x' and 'b' is
# minimum number of digits <------>
sprintf("%20.8d", 123) #=> " 00000123"
sprintf("%20.8o", 123) #=> " 00000173"
sprintf("%20.8x", 123) #=> " 0000007b"
sprintf("%20.8b", 123) #=> " 01111011"
sprintf("%20.8d", -123) #=> " -00000123"
sprintf("%20.8o", -123) #=> " ..777605"
sprintf("%20.8x", -123) #=> " ..ffff85"
sprintf("%20.8b", -11) #=> " ..110101"
# "0x" and "0b" for `#x' and `#b' is not counted for
# precision but "0" for `#o' is counted. <------>
sprintf("%#20.8d", 123) #=> " 00000123"
sprintf("%#20.8o", 123) #=> " 00000173"
sprintf("%#20.8x", 123) #=> " 0x0000007b"
sprintf("%#20.8b", 123) #=> " 0b01111011"
sprintf("%#20.8d", -123) #=> " -00000123"
sprintf("%#20.8o", -123) #=> " ..777605"
sprintf("%#20.8x", -123) #=> " 0x..ffff85"
sprintf("%#20.8b", -11) #=> " 0b..110101"
# precision for `e' is number of
# digits after the decimal point <------>
sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
# precision for `f' is number of
# digits after the decimal point <------>
sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
# precision for `g' is number of
# significant digits <------->
sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
# <------->
sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
# precision for `s' is
# maximum number of characters <------>
sprintf("%20.8s", "string test") #=> " string t"
Examples:
sprintf("%d %04x", 123, 123) #=> "123 007b"
sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
sprintf("%u", -123) #=> "-123"
For more complex formatting, Ruby supports a reference by name.
%s style uses format style, but %{name} style doesn't.
Examples:
sprintf("%d : %f", { :foo => 1, :bar => 2 })
#=> 1 : 2.000000
sprintf("%{foo}f", { :foo => 1 })
# => "1f"
;T;[o;=
;3I"
overload;F;40;;;50;)I",format(format_string [, arguments...] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @k;[ ;I"@return [String];T;0; @k;!F;6i ;>0;[[I""format_string[, arguments...];T0; @ko;=
;3I"
overload;F;40;;;50;)I"-sprintf(format_string [, arguments...] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @k;[ ;I"@return [String];T;0; @k;!F;6i ;>0;[[I""format_string[, arguments...];T0; @k;[ ;@g;0; @k;!F;"o;#;$T;%i;&i;'@$ ;(I"^static VALUE
f_sprintf(int c, const VALUE *v, VALUE _)
{
return rb_f_sprintf(c, v);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Integer;F;[[@c0;[[@i_
;T;:Integer;0;[ ;{ ;IC;"Converts arg to an Integer.
Numeric types are converted directly (with floating point numbers
being truncated). base (0, or between 2 and 36) is a base for
integer string representation. If arg is a String,
when base is omitted or equals zero, radix indicators
(0
, 0b
, and 0x
) are honored.
In any case, strings should be strictly conformed to numeric
representation. This behavior is different from that of
String#to_i. Non string values will be converted by first
trying to_int
, then to_i
.
Passing nil
raises a TypeError, while passing a String that
does not conform with numeric representation raises an ArgumentError.
This behavior can be altered by passing exception: false
,
in this case a not convertible value will return nil
.
Integer(123.999) #=> 123
Integer("0x1a") #=> 26
Integer(Time.new) #=> 1204973019
Integer("0930", 10) #=> 930
Integer("111", 2) #=> 7
Integer(nil) #=> TypeError: can't convert nil into Integer
Integer("x") #=> ArgumentError: invalid value for Integer(): "x"
Integer("x", exception: false) #=> nil
;T;[o;=
;3I"
overload;F;40;;;50;)I"*Integer(arg, base=0, exception: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Integer;TI"nil;T; @;[ ;I"@return [Integer, nil];T;0; @;!F;6i ;>0;[[I"arg;T0[I" base;TI"0;T[I"exception:;TI" true;T; @;[ ;I"Converts arg to an Integer.
Numeric types are converted directly (with floating point numbers
being truncated). base (0, or between 2 and 36) is a base for
integer string representation. If arg is a String,
when base is omitted or equals zero, radix indicators
(0
, 0b
, and 0x
) are honored.
In any case, strings should be strictly conformed to numeric
representation. This behavior is different from that of
String#to_i. Non string values will be converted by first
trying to_int
, then to_i
.
Passing nil
raises a TypeError, while passing a String that
does not conform with numeric representation raises an ArgumentError.
This behavior can be altered by passing exception: false
,
in this case a not convertible value will return nil
.
Integer(123.999) #=> 123
Integer("0x1a") #=> 26
Integer(Time.new) #=> 1204973019
Integer("0930", 10) #=> 930
Integer("111", 2) #=> 7
Integer(nil) #=> TypeError: can't convert nil into Integer
Integer("x") #=> ArgumentError: invalid value for Integer(): "x"
Integer("x", exception: false) #=> nil
@overload Integer(arg, base=0, exception: true)
@return [Integer, nil];T;0; @;!F;"o;#;$T;%i?
;&i\
;'@$ ;(I"static VALUE
rb_f_integer(int argc, VALUE *argv, VALUE obj)
{
VALUE arg = Qnil, opts = Qnil;
int base = 0;
if (argc > 1) {
int narg = 1;
VALUE vbase = rb_check_to_int(argv[1]);
if (!NIL_P(vbase)) {
base = NUM2INT(vbase);
narg = 2;
}
if (argc > narg) {
VALUE hash = rb_check_hash_type(argv[argc-1]);
if (!NIL_P(hash)) {
opts = rb_extract_keywords(&hash);
if (!hash) --argc;
}
}
}
rb_check_arity(argc, 1, 2);
arg = argv[0];
return rb_convert_to_integer(arg, base, opts_exception_p(opts));
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Float;F;[[@c0;[[@i;T;:
Float;0;[ ;{ ;IC;"Returns arg converted to a float. Numeric types are
converted directly, and with exception to String and
nil
the rest are converted using
arg.to_f
. Converting a String with invalid
characters will result in a ArgumentError. Converting
nil
generates a TypeError. Exceptions can be
suppressed by passing exception: false
.
Float(1) #=> 1.0
Float("123.456") #=> 123.456
Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring"
Float(nil) #=> TypeError: can't convert nil into Float
Float("123.0_badstring", exception: false) #=> nil
;T;[o;=
;3I"
overload;F;40;;;50;)I" Float(arg, exception: true);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Float;TI"nil;T; @;[ ;I"@return [Float, nil];T;0; @;!F;6i ;>0;[[I"arg;T0[I"exception:;TI" true;T; @;[ ;I"Returns arg converted to a float. Numeric types are
converted directly, and with exception to String and
nil
the rest are converted using
arg.to_f
. Converting a String with invalid
characters will result in a ArgumentError. Converting
nil
generates a TypeError. Exceptions can be
suppressed by passing exception: false
.
Float(1) #=> 1.0
Float("123.456") #=> 123.456
Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring"
Float(nil) #=> TypeError: can't convert nil into Float
Float("123.0_badstring", exception: false) #=> nil
@overload Float(arg, exception: true)
@return [Float, nil];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_float(int argc, VALUE *argv, VALUE obj)
{
VALUE arg = Qnil, opts = Qnil;
rb_scan_args(argc, argv, "1:", &arg, &opts);
return rb_convert_to_float(arg, opts_exception_p(opts));
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#String;F;[[I"arg;T0;[[@iY;T;:String;0;[ ;{ ;IC;"Returns arg as a String.
First tries to call its to_str
method, then its to_s
method.
String(self) #=> "main"
String(self.class) #=> "Object"
String(123456) #=> "123456"
;T;[o;=
;3I"
overload;F;40;;;50;)I"String(arg);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @;[ ;I"@return [String];T;0; @;!F;6i ;>0;[[I"arg;T0; @;[ ;I"
Returns arg as a String.
First tries to call its to_str
method, then its to_s
method.
String(self) #=> "main"
String(self.class) #=> "Object"
String(123456) #=> "123456"
@overload String(arg)
@return [String];T;0; @;!F;"o;#;$T;%iL;&iV;'@$ ;(I"Rstatic VALUE
rb_f_string(VALUE obj, VALUE arg)
{
return rb_String(arg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Array;F;[[I"arg;T0;[[@i;T;:
Array;0;[ ;{ ;IC;"Returns +arg+ as an Array.
First tries to call to_ary
on +arg+, then to_a
.
If +arg+ does not respond to to_ary
or to_a
,
returns an Array of length 1 containing +arg+.
If to_ary
or to_a
returns something other than
an Array, raises a TypeError.
Array(["a", "b"]) #=> ["a", "b"]
Array(1..5) #=> [1, 2, 3, 4, 5]
Array(key: :value) #=> [[:key, :value]]
Array(nil) #=> []
Array(1) #=> [1]
;T;[o;=
;3I"
overload;F;40;;;50;)I"Array(arg);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @ ;[ ;I"@return [Array];T;0; @ ;!F;6i ;>0;[[I"arg;T0; @ ;[ ;I""Returns +arg+ as an Array.
First tries to call to_ary
on +arg+, then to_a
.
If +arg+ does not respond to to_ary
or to_a
,
returns an Array of length 1 containing +arg+.
If to_ary
or to_a
returns something other than
an Array, raises a TypeError.
Array(["a", "b"]) #=> ["a", "b"]
Array(1..5) #=> [1, 2, 3, 4, 5]
Array(key: :value) #=> [[:key, :value]]
Array(nil) #=> []
Array(1) #=> [1]
@overload Array(arg)
@return [Array];T;0; @ ;!F;"o;#;$T;%ip;&i;'@$ ;(I"Pstatic VALUE
rb_f_array(VALUE obj, VALUE arg)
{
return rb_Array(arg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#Hash;F;[[I"arg;T0;[[@i;T;: Hash;0;[ ;{ ;IC;"Converts arg to a Hash by calling
arg.to_hash
. Returns an empty Hash when
arg is nil or [].
Hash([]) #=> {}
Hash(nil) #=> {}
Hash(key: :value) #=> {:key => :value}
Hash([1, 2, 3]) #=> TypeError
;T;[o;=
;3I"
overload;F;40;;;50;)I"Hash(arg);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I" Hash;T; @;[ ;I"@return [Hash];T;0; @;!F;6i ;>0;[[I"arg;T0; @;[ ;I"<Converts arg to a Hash by calling
arg.to_hash
. Returns an empty Hash when
arg is nil or [].
Hash([]) #=> {}
Hash(nil) #=> {}
Hash(key: :value) #=> {:key => :value}
Hash([1, 2, 3]) #=> TypeError
@overload Hash(arg)
@return [Hash];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"Nstatic VALUE
rb_f_hash(VALUE obj, VALUE arg)
{
return rb_Hash(arg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#srand;F;[[@c0;[[I"
random.c;Ti;T;:
srand;0;[ ;{ ;IC;"zSeeds the system pseudo-random number generator, Random::DEFAULT, with
+number+. The previous seed value is returned.
If +number+ is omitted, seeds the generator using a source of entropy
provided by the operating system, if available (/dev/urandom on Unix systems
or the RSA cryptographic provider on Windows), which is then combined with
the time, the process id, and a sequence number.
srand may be used to ensure repeatable sequences of pseudo-random numbers
between different runs of the program. By setting the seed to a known value,
programs can be made deterministic during testing.
srand 1234 # => 268519324636777531569100071560086917274
[ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
[ rand(10), rand(1000) ] # => [4, 664]
srand 1234 # => 1234
[ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
;T;[o;=
;3I"
overload;F;40;;;50;)I"$srand(number = Random.new_seed);T;IC;" ;T;[ ;[ ;I" ;T;0; @>;!F;6i ;>0;[[I"number;TI"Random.new_seed;T; @>;[ ;I"Seeds the system pseudo-random number generator, Random::DEFAULT, with
+number+. The previous seed value is returned.
If +number+ is omitted, seeds the generator using a source of entropy
provided by the operating system, if available (/dev/urandom on Unix systems
or the RSA cryptographic provider on Windows), which is then combined with
the time, the process id, and a sequence number.
srand may be used to ensure repeatable sequences of pseudo-random numbers
between different runs of the program. By setting the seed to a known value,
programs can be made deterministic during testing.
srand 1234 # => 268519324636777531569100071560086917274
[ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
[ rand(10), rand(1000) ] # => [4, 664]
srand 1234 # => 1234
[ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
@overload srand(number = Random.new_seed);T;0; @>;!F;"o;#;$T;%i;&i;'@$ ;(I"Astatic VALUE
rb_f_srand(int argc, VALUE *argv, VALUE obj)
{
VALUE seed, old;
rb_random_t *r = &default_rand;
if (rb_check_arity(argc, 0, 1) == 0) {
seed = random_seed(obj);
}
else {
seed = rb_to_int(argv[0]);
}
old = r->seed;
r->seed = rand_init(&r->mt, seed);
return old;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#rand;F;[[@c0;[[@DiV;T;: rand;0;[ ;{ ;IC;"0If called without an argument, or if max.to_i.abs == 0, rand
returns a pseudo-random floating point number between 0.0 and 1.0,
including 0.0 and excluding 1.0.
rand #=> 0.2725926052826416
When +max.abs+ is greater than or equal to 1, +rand+ returns a pseudo-random
integer greater than or equal to 0 and less than +max.to_i.abs+.
rand(100) #=> 12
When +max+ is a Range, +rand+ returns a random number where
range.member?(number) == true.
Negative or floating point values for +max+ are allowed, but may give
surprising results.
rand(-100) # => 87
rand(-0.5) # => 0.8130921818028143
rand(1.9) # equivalent to rand(1), which is always 0
Kernel.srand may be used to ensure that sequences of random numbers are
reproducible between different runs of a program.
See also Random.rand.
;T;[o;=
;3I"
overload;F;40;;;50;)I"rand(max=0);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Numeric;T; @Y;[ ;I"@return [Numeric];T;0; @Y;!F;6i ;>0;[[I"max;TI"0;T; @Y;[ ;I"\If called without an argument, or if max.to_i.abs == 0, rand
returns a pseudo-random floating point number between 0.0 and 1.0,
including 0.0 and excluding 1.0.
rand #=> 0.2725926052826416
When +max.abs+ is greater than or equal to 1, +rand+ returns a pseudo-random
integer greater than or equal to 0 and less than +max.to_i.abs+.
rand(100) #=> 12
When +max+ is a Range, +rand+ returns a random number where
range.member?(number) == true.
Negative or floating point values for +max+ are allowed, but may give
surprising results.
rand(-100) # => 87
rand(-0.5) # => 0.8130921818028143
rand(1.9) # equivalent to rand(1), which is always 0
Kernel.srand may be used to ensure that sequences of random numbers are
reproducible between different runs of a program.
See also Random.rand.
@overload rand(max=0)
@return [Numeric];T;0; @Y;!F;"o;#;$T;%i7;&iS;'@$ ;(I"static VALUE
rb_f_rand(int argc, VALUE *argv, VALUE obj)
{
VALUE vmax;
rb_random_t *rnd = rand_start(&default_rand);
if (rb_check_arity(argc, 0, 1) && !NIL_P(vmax = argv[0])) {
VALUE v = rand_range(Qnil, rnd, vmax);
if (v != Qfalse) return v;
vmax = rb_to_int(vmax);
if (vmax != INT2FIX(0)) {
v = rand_int(Qnil, rnd, vmax, 0);
if (!NIL_P(v)) return v;
}
}
return DBL2NUM(genrand_real(&rnd->mt));
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#caller;F;[[@c0;[[I"vm_backtrace.c;Ti;T;:caller;0;[ ;{ ;IC;"Returns the current execution stack---an array containing strings in
the form file:line
or file:line: in
`method'
.
The optional _start_ parameter determines the number of initial stack
entries to omit from the top of the stack.
A second optional +length+ parameter can be used to limit how many entries
are returned from the stack.
Returns +nil+ if _start_ is greater than the size of
current execution stack.
Optionally you can pass a range, which will return an array containing the
entries within the specified range.
def a(skip)
caller(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end
c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `'"]
c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `'"]
c(2) #=> ["prog:8:in `c'", "prog:12:in `'"]
c(3) #=> ["prog:13:in `'"]
c(4) #=> []
c(5) #=> nil
;T;[o;=
;3I"
overload;F;40;;;50;)I" caller(start=1, length=nil);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;TI"nil;T; @x;[ ;I"@return [Array, nil];T;0; @x;!F;6i ;>0;[[I"
start;TI"1;T[I"length;TI"nil;T; @xo;=
;3I"
overload;F;40;;;50;)I"caller(range);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;TI"nil;T; @x;[ ;I"@return [Array, nil];T;0; @x;!F;6i ;>0;[[I"
range;T0; @x;[ ;I"$Returns the current execution stack---an array containing strings in
the form file:line
or file:line: in
`method'
.
The optional _start_ parameter determines the number of initial stack
entries to omit from the top of the stack.
A second optional +length+ parameter can be used to limit how many entries
are returned from the stack.
Returns +nil+ if _start_ is greater than the size of
current execution stack.
Optionally you can pass a range, which will return an array containing the
entries within the specified range.
def a(skip)
caller(skip)
end
def b(skip)
a(skip)
end
def c(skip)
b(skip)
end
c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `'"]
c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `'"]
c(2) #=> ["prog:8:in `c'", "prog:12:in `'"]
c(3) #=> ["prog:13:in `'"]
c(4) #=> []
c(5) #=> nil
@overload caller(start=1, length=nil)
@return [Array, nil]
@overload caller(range)
@return [Array, nil];T;0; @x;!F;"o;#;$T;%i;&i;'@$ ;(I"{static VALUE
rb_f_caller(int argc, VALUE *argv, VALUE _)
{
return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 1);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#caller_locations;F;[[@c0;[[@~i
;T;:caller_locations;0;[ ;{ ;IC;"&Returns the current execution stack---an array containing
backtrace location objects.
See Thread::Backtrace::Location for more information.
The optional _start_ parameter determines the number of initial stack
entries to omit from the top of the stack.
A second optional +length+ parameter can be used to limit how many entries
are returned from the stack.
Returns +nil+ if _start_ is greater than the size of
current execution stack.
Optionally you can pass a range, which will return an array containing the
entries within the specified range.
;T;[o;=
;3I"
overload;F;40;;;50;)I":caller_locations(start=1, length=nil) -> array or nil;T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"
start;TI"1;T[I"length;TI"nil;T; @o;=
;3I"
overload;F;40;;;50;)I".caller_locations(range) -> array or nil;T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"
range;T0; @;[ ;I"Returns the current execution stack---an array containing
backtrace location objects.
See Thread::Backtrace::Location for more information.
The optional _start_ parameter determines the number of initial stack
entries to omit from the top of the stack.
A second optional +length+ parameter can be used to limit how many entries
are returned from the stack.
Returns +nil+ if _start_ is greater than the size of
current execution stack.
Optionally you can pass a range, which will return an array containing the
entries within the specified range.
@overload caller_locations(start=1, length=nil) -> array or nil
@overload caller_locations(range) -> array or nil;T;0; @;!F;"o;#;$T;%i;&i
;'@$ ;(I"static VALUE
rb_f_caller_locations(int argc, VALUE *argv, VALUE _)
{
return ec_backtrace_to_ary(GET_EC(), argc, argv, 1, 1, 0);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#at_exit;F;[ ;[[I"eval_jump.c;Ti*;T;:at_exit;0;[ ;{ ;IC;"Converts _block_ to a +Proc+ object (and therefore
binds it at the point of call) and registers it for execution when
the program exits. If multiple handlers are registered, they are
executed in reverse order of registration.
def do_at_exit(str1)
at_exit { print str1 }
end
at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit
produces:
goodbye cruel world
;T;[o;=
;3I"
overload;F;40;;;50;)I"at_exit;T;IC;" ;T;[o;2
;3I"
yield;F;4I"[];T;0;50; @o;2
;3I"return;F;4I" ;T;0;5[I" Proc;T; @;[ ;I"@yield []
@return [Proc];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Converts _block_ to a +Proc+ object (and therefore
binds it at the point of call) and registers it for execution when
the program exits. If multiple handlers are registered, they are
executed in reverse order of registration.
def do_at_exit(str1)
at_exit { print str1 }
end
at_exit { puts "cruel world" }
do_at_exit("goodbye ")
exit
produces:
goodbye cruel world
@overload at_exit
@yield []
@return [Proc];T;0; @;!F;"o;#;$T;%i;&i(;'@$ ;(I"static VALUE
rb_f_at_exit(VALUE _)
{
VALUE proc;
if (!rb_block_given_p()) {
rb_raise(rb_eArgError, "called without a block");
}
proc = rb_block_proc();
rb_set_end_proc(rb_call_end_proc, proc);
return proc;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#proc;F;[ ;[[@iQ;T;: proc;0;[ ;{ ;IC;"Equivalent to Proc.new.
;T;[o;=
;3I"
overload;F;40;;;50;)I" proc;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"...;T; @o;2
;3I"return;F;4I" ;T;0;5[I" Proc;T; @;[ ;I" @yield [...]
@return [Proc];T;0; @;!F;6i ;>0;[ ; @;[ ;I"MEquivalent to Proc.new.
@overload proc
@yield [...]
@return [Proc];T;0; @;!F;"o;#;$T;%iJ;&iO;'@$ ;(I"Qstatic VALUE
f_proc(VALUE _)
{
return proc_new(rb_cProc, FALSE, TRUE);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#lambda;F;[ ;[[@ie;T;:lambda;0;[ ;{ ;IC;"qEquivalent to Proc.new, except the resulting Proc objects check the
number of parameters passed when called.
;T;[o;=
;3I"
overload;F;40;;;50;)I"lambda;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"...;T; @o;2
;3I"return;F;4I" ;T;0;5[I" Proc;T; @;[ ;I" @yield [...]
@return [Proc];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Equivalent to Proc.new, except the resulting Proc objects check the
number of parameters passed when called.
@overload lambda
@yield [...]
@return [Proc];T;0; @;!F;"o;#;$T;%i];⁣'@$ ;(I"Estatic VALUE
f_lambda(VALUE _)
{
return rb_block_lambda();
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#binding;F;[ ;[[@i;T;:binding;0;[ ;{ ;IC;"YReturns a +Binding+ object, describing the variable and
method bindings at the point of call. This object can be used when
calling +eval+ to execute the evaluated command in this
environment. See also the description of class +Binding+.
def get_binding(param)
binding
end
b = get_binding("hello")
eval("param", b) #=> "hello"
;T;[o;=
;3I"
overload;F;40;;;50;)I"binding;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Binding;T; @2;[ ;I"@return [Binding];T;0; @2;!F;6i ;>0;[ ; @2;[ ;I"Returns a +Binding+ object, describing the variable and
method bindings at the point of call. This object can be used when
calling +eval+ to execute the evaluated command in this
environment. See also the description of class +Binding+.
def get_binding(param)
binding
end
b = get_binding("hello")
eval("param", b) #=> "hello"
@overload binding
@return [Binding];T;0; @2;!F;"o;#;$T;%ir;&i;'@$ ;(I"Kstatic VALUE
rb_f_binding(VALUE self)
{
return rb_binding_new();
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#eval;F;[[@c0;[[@di;T;: eval;0;[ ;{ ;IC;"Evaluates the Ruby expression(s) in string. If
binding is given, which must be a Binding object, the
evaluation is performed in its context. If the optional
filename and lineno parameters are present, they
will be used when reporting syntax errors.
def get_binding(str)
return binding
end
str = "hello"
eval "str + ' Fred'" #=> "hello Fred"
eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
;T;[o;=
;3I"
overload;F;40;;;50;)I"4eval(string [, binding [, filename [,lineno]]]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @M;[ ;I"@return [Object];T;0; @M;!F;6i ;>0;[[I"-string[, binding [, filename [,lineno]]];T0; @M;[ ;I"*Evaluates the Ruby expression(s) in string. If
binding is given, which must be a Binding object, the
evaluation is performed in its context. If the optional
filename and lineno parameters are present, they
will be used when reporting syntax errors.
def get_binding(str)
return binding
end
str = "hello"
eval "str + ' Fred'" #=> "hello Fred"
eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
@overload eval(string [, binding [, filename [,lineno]]])
@return [Object];T;0; @M;!F;"o;#;$T;%is;&i;'@$ ;(I"VALUE
rb_f_eval(int argc, const VALUE *argv, VALUE self)
{
VALUE src, scope, vfile, vline;
VALUE file = Qundef;
int line = 1;
rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
SafeStringValue(src);
if (argc >= 3) {
StringValue(vfile);
}
if (argc >= 4) {
line = NUM2INT(vline);
}
if (!NIL_P(vfile))
file = vfile;
if (NIL_P(scope))
return eval_string_with_cref(self, src, NULL, file, line);
else
return eval_string_with_scope(scope, src, file, line);
};T;)I"
VALUE;T;*To;;F;
;;;;I"Kernel#local_variables;F;[ ;[[@diU ;T;:local_variables;0;[ ;{ ;IC;"Returns the names of the current local variables.
fred = 1
for i in 1..10
# ...
end
local_variables #=> [:fred, :i]
;T;[o;=
;3I"
overload;F;40;;;50;)I"local_variables;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"
Array;T; @k;[ ;I"@return [Array];T;0; @k;!F;6i ;>0;[ ; @k;[ ;I"Returns the names of the current local variables.
fred = 1
for i in 1..10
# ...
end
local_variables #=> [:fred, :i]
@overload local_variables
@return [Array];T;0; @k;!F;"o;#;$T;%iH ;&iR ;'@$ ;(I"static VALUE
rb_f_local_variables(VALUE _)
{
struct local_var_list vars;
rb_execution_context_t *ec = GET_EC();
rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp));
unsigned int i;
local_var_list_init(&vars);
while (cfp) {
if (cfp->iseq) {
for (i = 0; i < cfp->iseq->body->local_table_size; i++) {
local_var_list_add(&vars, cfp->iseq->body->local_table[i]);
}
}
if (!VM_ENV_LOCAL_P(cfp->ep)) {
/* block */
const VALUE *ep = VM_CF_PREV_EP(cfp);
if (vm_collect_local_variables_in_heap(ep, &vars)) {
break;
}
else {
while (cfp->ep != ep) {
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
}
}
}
else {
break;
}
}
return local_var_list_finish(&vars);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#iterator?;F;[ ;[[@di ;T;:iterator?;0;[ ;{ ;IC;"\Returns true
if yield
would execute a
block in the current context. The iterator?
form
is mildly deprecated.
def try
if block_given?
yield
else
"no block"
end
end
try #=> "no block"
try { "hello" } #=> "hello"
try do "hello" end #=> "hello";T;[o;=
;3I"
overload;F;40;:block_given?;50;)I"block_given?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @o;=
;3I"
overload;F;40;;;50;)I"iterator?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;I"Returns true
if yield
would execute a
block in the current context. The iterator?
form
is mildly deprecated.
def try
if block_given?
yield
else
"no block"
end
end
try #=> "no block"
try { "hello" } #=> "hello"
try do "hello" end #=> "hello"
@overload block_given?
@return [Boolean]
@overload iterator?
@return [Boolean];T;0; @;!F;"o;#;$T;%ix ;&i ;6i ;'@$ ;(I"Rstatic VALUE
rb_f_block_given_p(VALUE _)
{
rb_execution_context_t *ec = GET_EC();
rb_control_frame_t *cfp = ec->cfp;
cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) {
return Qtrue;
}
else {
return Qfalse;
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#block_given?;F;[ ;[[@di ;T;;;0;[ ;{ ;IC;"\Returns true
if yield
would execute a
block in the current context. The iterator?
form
is mildly deprecated.
def try
if block_given?
yield
else
"no block"
end
end
try #=> "no block"
try { "hello" } #=> "hello"
try do "hello" end #=> "hello";T;[o;=
;3I"
overload;F;40;;;50;)I"block_given?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @o;=
;3I"
overload;F;40;;;50;)I"iterator?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;@;0; @;!F;"o;#;$T;%ix ;&i ;6i ;'@$ ;(I"Rstatic VALUE
rb_f_block_given_p(VALUE _)
{
rb_execution_context_t *ec = GET_EC();
rb_control_frame_t *cfp = ec->cfp;
cfp = vm_get_ruby_level_caller_cfp(ec, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp));
if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) {
return Qtrue;
}
else {
return Qfalse;
}
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#catch;F;[[@c0;[[@di;T;:
catch;0;[ ;{ ;IC;"+catch+ executes its block. If +throw+ is not called, the block executes
normally, and +catch+ returns the value of the last expression evaluated.
catch(1) { 123 } # => 123
If throw(tag2, val)
is called, Ruby searches up its stack for
a +catch+ block whose +tag+ has the same +object_id+ as _tag2_. When found,
the block stops executing and returns _val_ (or +nil+ if no second argument
was given to +throw+).
catch(1) { throw(1, 456) } # => 456
catch(1) { throw(1) } # => nil
When +tag+ is passed as the first argument, +catch+ yields it as the
parameter of the block.
catch(1) {|x| x + 2 } # => 3
When no +tag+ is given, +catch+ yields a new unique object (as from
+Object.new+) as the block parameter. This object can then be used as the
argument to +throw+, and will match the correct +catch+ block.
catch do |obj_A|
catch do |obj_B|
throw(obj_B, 123)
puts "This puts is not reached"
end
puts "This puts is displayed"
456
end
# => 456
catch do |obj_A|
catch do |obj_B|
throw(obj_A, 123)
puts "This puts is still not reached"
end
puts "Now this puts is also not reached"
456
end
# => 123
;T;[o;=
;3I"
overload;F;40;;;50;)I"catch([tag]);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"tag;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I""@yield [tag]
@return [Object];T;0; @;!F;6i ;>0;[[I"
[tag];T0; @;[ ;I"+catch+ executes its block. If +throw+ is not called, the block executes
normally, and +catch+ returns the value of the last expression evaluated.
catch(1) { 123 } # => 123
If throw(tag2, val)
is called, Ruby searches up its stack for
a +catch+ block whose +tag+ has the same +object_id+ as _tag2_. When found,
the block stops executing and returns _val_ (or +nil+ if no second argument
was given to +throw+).
catch(1) { throw(1, 456) } # => 456
catch(1) { throw(1) } # => nil
When +tag+ is passed as the first argument, +catch+ yields it as the
parameter of the block.
catch(1) {|x| x + 2 } # => 3
When no +tag+ is given, +catch+ yields a new unique object (as from
+Object.new+) as the block parameter. This object can then be used as the
argument to +throw+, and will match the correct +catch+ block.
catch do |obj_A|
catch do |obj_B|
throw(obj_B, 123)
puts "This puts is not reached"
end
puts "This puts is displayed"
456
end
# => 456
catch do |obj_A|
catch do |obj_B|
throw(obj_A, 123)
puts "This puts is still not reached"
end
puts "Now this puts is also not reached"
456
end
# => 123
@overload catch([tag])
@yield [tag]
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@$ ;(I"static VALUE
rb_f_catch(int argc, VALUE *argv, VALUE self)
{
VALUE tag = rb_check_arity(argc, 0, 1) ? argv[0] : rb_obj_alloc(rb_cObject);
return rb_catch_obj(tag, catch_i, 0);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#throw;F;[[@c0;[[@di;T;:
throw;0;[ ;{ ;IC;"$Transfers control to the end of the active +catch+ block
waiting for _tag_. Raises +UncaughtThrowError+ if there
is no +catch+ block for the _tag_. The optional second
parameter supplies a return value for the +catch+ block,
which otherwise defaults to +nil+. For examples, see
Kernel::catch.
;T;[o;=
;3I"
overload;F;40;;;50;)I"throw(tag [, obj]);T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"tag[, obj];T0; @;[ ;I"CTransfers control to the end of the active +catch+ block
waiting for _tag_. Raises +UncaughtThrowError+ if there
is no +catch+ block for the _tag_. The optional second
parameter supplies a return value for the +catch+ block,
which otherwise defaults to +nil+. For examples, see
Kernel::catch.
@overload throw(tag [, obj]);T;0; @;!F;"o;#;$T;%i|;&i;'@$ ;(I"static VALUE
rb_f_throw(int argc, VALUE *argv, VALUE _)
{
VALUE tag, value;
rb_scan_args(argc, argv, "11", &tag, &value);
rb_throw_obj(tag, value);
UNREACHABLE_RETURN(Qnil);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#loop;F;[ ;[[@dia;T;: loop;0;[ ;{ ;IC;"Repeatedly executes the block.
If no block is given, an enumerator is returned instead.
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
StopIteration raised in the block breaks the loop. In this case,
loop returns the "result" value stored in the exception.
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}
result = loop {
puts enum.next
} #=> :ok
;T;[o;=
;3I"
overload;F;40;;;50;)I" loop;T;IC;" ;T;[o;2
;3I"
yield;F;4I"[];T;0;50; @;[ ;I"@yield [];T;0; @;!F;6i ;>0;[ ; @o;=
;3I"
overload;F;40;;;50;)I" loop;T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[ ; @;[ ;I"Repeatedly executes the block.
If no block is given, an enumerator is returned instead.
loop do
print "Input: "
line = gets
break if !line or line =~ /^qQ/
# ...
end
StopIteration raised in the block breaks the loop. In this case,
loop returns the "result" value stored in the exception.
enum = Enumerator.new { |y|
y << "one"
y << "two"
:ok
}
result = loop {
puts enum.next
} #=> :ok
@overload loop
@yield []
@overload loop;T;0; @;!F;"o;#;$T;%iC;&i^;'@$ ;(I"static VALUE
rb_f_loop(VALUE self)
{
RETURN_SIZED_ENUMERATOR(self, 0, 0, rb_f_loop_size);
return rb_rescue2(loop_i, (VALUE)0, loop_stop, (VALUE)0, rb_eStopIteration, (VALUE)0);
};T;)I"static VALUE;T;*To;;F;
;;;;I"(Kernel#register_sample_bug_reporter;F;[[I"obj;T0;[[I"+ext/-test-/bug_reporter/bug_reporter.c;Ti;T;:!register_sample_bug_reporter;0;[ ;{ ;IC;" ;T;[ ;[ ;@|;0; @2;'@$ ;(I"static VALUE
register_sample_bug_reporter(VALUE self, VALUE obj)
{
rb_bug_reporter_add(sample_bug_reporter, (void *)(uintptr_t)NUM2INT(obj));
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Kernel#test;F;[[@c0;[[I"file.c;Ti;T;: test;0;[ ;{ ;IC;" Uses the character +cmd+ to perform various tests on +file1+ (first
table below) or on +file1+ and +file2+ (second table).
File tests on a single file:
Cmd Returns Meaning
"A" | Time | Last access time for file1
"b" | boolean | True if file1 is a block device
"c" | boolean | True if file1 is a character device
"C" | Time | Last change time for file1
"d" | boolean | True if file1 exists and is a directory
"e" | boolean | True if file1 exists
"f" | boolean | True if file1 exists and is a regular file
"g" | boolean | True if file1 has the \CF{setgid} bit
| | set (false under NT)
"G" | boolean | True if file1 exists and has a group
| | ownership equal to the caller's group
"k" | boolean | True if file1 exists and has the sticky bit set
"l" | boolean | True if file1 exists and is a symbolic link
"M" | Time | Last modification time for file1
"o" | boolean | True if file1 exists and is owned by
| | the caller's effective uid
"O" | boolean | True if file1 exists and is owned by
| | the caller's real uid
"p" | boolean | True if file1 exists and is a fifo
"r" | boolean | True if file1 is readable by the effective
| | uid/gid of the caller
"R" | boolean | True if file is readable by the real
| | uid/gid of the caller
"s" | int/nil | If file1 has nonzero size, return the size,
| | otherwise return nil
"S" | boolean | True if file1 exists and is a socket
"u" | boolean | True if file1 has the setuid bit set
"w" | boolean | True if file1 exists and is writable by
| | the effective uid/gid
"W" | boolean | True if file1 exists and is writable by
| | the real uid/gid
"x" | boolean | True if file1 exists and is executable by
| | the effective uid/gid
"X" | boolean | True if file1 exists and is executable by
| | the real uid/gid
"z" | boolean | True if file1 exists and has a zero length
Tests that take two files:
"-" | boolean | True if file1 and file2 are identical
"=" | boolean | True if the modification times of file1
| | and file2 are equal
"<" | boolean | True if the modification time of file1
| | is prior to that of file2
">" | boolean | True if the modification time of file1
| | is after that of file2
;T;[o;=
;3I"
overload;F;40;;;50;)I" test(cmd, file1 [, file2] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @A;[ ;I"@return [Object];T;0; @A;!F;6i ;>0;[[I"cmd;T0[I"file1[, file2];T0; @A;[ ;I" Uses the character +cmd+ to perform various tests on +file1+ (first
table below) or on +file1+ and +file2+ (second table).
File tests on a single file:
Cmd Returns Meaning
"A" | Time | Last access time for file1
"b" | boolean | True if file1 is a block device
"c" | boolean | True if file1 is a character device
"C" | Time | Last change time for file1
"d" | boolean | True if file1 exists and is a directory
"e" | boolean | True if file1 exists
"f" | boolean | True if file1 exists and is a regular file
"g" | boolean | True if file1 has the \CF{setgid} bit
| | set (false under NT)
"G" | boolean | True if file1 exists and has a group
| | ownership equal to the caller's group
"k" | boolean | True if file1 exists and has the sticky bit set
"l" | boolean | True if file1 exists and is a symbolic link
"M" | Time | Last modification time for file1
"o" | boolean | True if file1 exists and is owned by
| | the caller's effective uid
"O" | boolean | True if file1 exists and is owned by
| | the caller's real uid
"p" | boolean | True if file1 exists and is a fifo
"r" | boolean | True if file1 is readable by the effective
| | uid/gid of the caller
"R" | boolean | True if file is readable by the real
| | uid/gid of the caller
"s" | int/nil | If file1 has nonzero size, return the size,
| | otherwise return nil
"S" | boolean | True if file1 exists and is a socket
"u" | boolean | True if file1 has the setuid bit set
"w" | boolean | True if file1 exists and is writable by
| | the effective uid/gid
"W" | boolean | True if file1 exists and is writable by
| | the real uid/gid
"x" | boolean | True if file1 exists and is executable by
| | the effective uid/gid
"X" | boolean | True if file1 exists and is executable by
| | the real uid/gid
"z" | boolean | True if file1 exists and has a zero length
Tests that take two files:
"-" | boolean | True if file1 and file2 are identical
"=" | boolean | True if the modification times of file1
| | and file2 are equal
"<" | boolean | True if the modification time of file1
| | is prior to that of file2
">" | boolean | True if the modification time of file1
| | is after that of file2
@overload test(cmd, file1 [, file2] )
@return [Object];T;0; @A;!F;"o;#;$T;%i;&i;'@$ ;(I"lstatic VALUE
rb_f_test(int argc, VALUE *argv, VALUE _)
{
int cmd;
if (argc == 0) rb_check_arity(argc, 2, 3);
cmd = NUM2CHR(argv[0]);
if (cmd == 0) {
unknown:
/* unknown command */
if (ISPRINT(cmd)) {
rb_raise(rb_eArgError, "unknown command '%s%c'", cmd == '\'' || cmd == '\\' ? "\\" : "", cmd);
}
else {
rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd);
}
}
if (strchr("bcdefgGkloOprRsSuwWxXz", cmd)) {
CHECK(1);
switch (cmd) {
case 'b':
return rb_file_blockdev_p(0, argv[1]);
case 'c':
return rb_file_chardev_p(0, argv[1]);
case 'd':
return rb_file_directory_p(0, argv[1]);
case 'e':
return rb_file_exist_p(0, argv[1]);
case 'f':
return rb_file_file_p(0, argv[1]);
case 'g':
return rb_file_sgid_p(0, argv[1]);
case 'G':
return rb_file_grpowned_p(0, argv[1]);
case 'k':
return rb_file_sticky_p(0, argv[1]);
case 'l':
return rb_file_symlink_p(0, argv[1]);
case 'o':
return rb_file_owned_p(0, argv[1]);
case 'O':
return rb_file_rowned_p(0, argv[1]);
case 'p':
return rb_file_pipe_p(0, argv[1]);
case 'r':
return rb_file_readable_p(0, argv[1]);
case 'R':
return rb_file_readable_real_p(0, argv[1]);
case 's':
return rb_file_size_p(0, argv[1]);
case 'S':
return rb_file_socket_p(0, argv[1]);
case 'u':
return rb_file_suid_p(0, argv[1]);
case 'w':
return rb_file_writable_p(0, argv[1]);
case 'W':
return rb_file_writable_real_p(0, argv[1]);
case 'x':
return rb_file_executable_p(0, argv[1]);
case 'X':
return rb_file_executable_real_p(0, argv[1]);
case 'z':
return rb_file_zero_p(0, argv[1]);
}
}
if (strchr("MAC", cmd)) {
struct stat st;
VALUE fname = argv[1];
CHECK(1);
if (rb_stat(fname, &st) == -1) {
int e = errno;
FilePathValue(fname);
rb_syserr_fail_path(e, fname);
}
switch (cmd) {
case 'A':
return stat_atime(&st);
case 'M':
return stat_mtime(&st);
case 'C':
return stat_ctime(&st);
}
}
if (cmd == '-') {
CHECK(2);
return rb_file_identical_p(0, argv[1], argv[2]);
}
if (strchr("=<>", cmd)) {
struct stat st1, st2;
struct timespec t1, t2;
CHECK(2);
if (rb_stat(argv[1], &st1) < 0) return Qfalse;
if (rb_stat(argv[2], &st2) < 0) return Qfalse;
t1 = stat_mtimespec(&st1);
t2 = stat_mtimespec(&st2);
switch (cmd) {
case '=':
if (t1.tv_sec == t2.tv_sec && t1.tv_nsec == t2.tv_nsec) return Qtrue;
return Qfalse;
case '>':
if (t1.tv_sec > t2.tv_sec) return Qtrue;
if (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec) return Qtrue;
return Qfalse;
case '<':
if (t1.tv_sec < t2.tv_sec) return Qtrue;
if (t1.tv_sec == t2.tv_sec && t1.tv_nsec < t2.tv_nsec) return Qtrue;
return Qfalse;
}
}
goto unknown;
};T;)I"static VALUE;T;*T;A@$ ;BIC;[ ;A@$ ;CIC;[ ;A@$ ;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@i[@i;T;:Kernel;;K;;;[ ;{ ;IC;"FThe Kernel module is included by class Object, so its methods are
available in every Ruby object.
The Kernel instance methods are documented in class Object while the
module methods are documented here. These methods are called without a
receiver and thus can be called in functional form:
sprintf "%.1f", 1.234 #=> "1.2";T;[ ;[ ;I"I
The Kernel module is included by class Object, so its methods are
available in every Ruby object.
The Kernel instance methods are documented in class Object while the
module methods are documented here. These methods are called without a
receiver and thus can be called in functional form:
sprintf "%.1f", 1.234 #=> "1.2"
;T;0; @$ ;!F;"o;#;$T;%i;&i;6i ;'@;I"Kernel;F;A@];DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@iq[@i5[@i;T;;T;;K;;;[ ;{ ;IC;"Object is the default root of all Ruby objects. Object inherits from
BasicObject which allows creating alternate object hierarchies. Methods
on Object are available to all classes unless explicitly overridden.
Object mixes in the Kernel module, making the built-in kernel functions
globally accessible. Although the instance methods of Object are defined
by the Kernel module, we have chosen to document them here for clarity.
When referencing constants in classes inheriting from Object you do not
need to use the full namespace. For example, referencing +File+ inside
+YourClass+ will find the top-level File class.
In the descriptions of Object's methods, the parameter symbol refers
to a symbol, which is either a quoted string or a Symbol (such as
:name
).;T;[ ;[ ;I"
Object is the default root of all Ruby objects. Object inherits from
BasicObject which allows creating alternate object hierarchies. Methods
on Object are available to all classes unless explicitly overridden.
Object mixes in the Kernel module, making the built-in kernel functions
globally accessible. Although the instance methods of Object are defined
by the Kernel module, we have chosen to document them here for clarity.
When referencing constants in classes inheriting from Object you do not
need to use the full namespace. For example, referencing +File+ inside
+YourClass+ will find the top-level File class.
In the descriptions of Object's methods, the parameter symbol refers
to a symbol, which is either a quoted string or a Symbol (such as
:name
).
;T;0; @];!F;"o;#;$T;%iq;&i;6i ;'@;I"Object;F;So;
;IC;[o;;F;
;;:private;I"BasicObject#initialize;F;[ ;[[@i};T;:initialize;0;[ ;{ ;IC;"=call-seq:
BasicObject.new
Returns a new BasicObject.
;T;[ ;[ ;I"?
call-seq:
BasicObject.new
Returns a new BasicObject.
;T;0; @;!F;"o;#;$T;%ij;&io;'@;(I"Gstatic VALUE
rb_obj_dummy0(VALUE _)
{
return rb_obj_dummy();
};T;)I"static VALUE;T;*To;;F;
;;;;I"BasicObject#==;F;[[I" obj2;T0;[[@i;T;;`;0;[ ;{ ;IC;"Equality --- At the Object level, #== returns true
only if +obj+ and +other+ are the same object. Typically, this
method is overridden in descendant classes to provide
class-specific meaning.
Unlike #==, the #equal? method should never be overridden by
subclasses as it is used to determine object identity (that is,
a.equal?(b)
if and only if a
is the same
object as b
):
obj = "a"
other = obj.dup
obj == other #=> true
obj.equal? other #=> false
obj.equal? obj #=> true
The #eql? method returns true
if +obj+ and +other+
refer to the same hash key. This is used by Hash to test members
for equality. For any pair of objects where #eql? returns +true+,
the #hash value of both objects must be equal. So any subclass
that overrides #eql? should also override #hash appropriately.
For objects of class Object, #eql? is synonymous
with #==. Subclasses normally continue this tradition by aliasing
#eql? to their overridden #== method, but there are exceptions.
Numeric types, for example, perform type conversion across #==,
but not across #eql?, so:
1 == 1.0 #=> true
1.eql? 1.0 #=> false
;T;[o;=
;3I"
overload;F;40;;`;50;)I"==(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @o;=
;3I"
overload;F;40;;a;50;)I"equal?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @o;=
;3I"
overload;F;40;;_;50;)I"eql?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @;[ ;@y;0; @;!F;"o;#;$T;%i;&i;'@;(I"}MJIT_FUNC_EXPORTED VALUE
rb_obj_equal(VALUE obj1, VALUE obj2)
{
if (obj1 == obj2) return Qtrue;
return Qfalse;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"BasicObject#equal?;F;[[I" obj2;T0;[[@i;T;;a;0;[ ;{ ;IC;"Equality --- At the Object level, #== returns true
only if +obj+ and +other+ are the same object. Typically, this
method is overridden in descendant classes to provide
class-specific meaning.
Unlike #==, the #equal? method should never be overridden by
subclasses as it is used to determine object identity (that is,
a.equal?(b)
if and only if a
is the same
object as b
):
obj = "a"
other = obj.dup
obj == other #=> true
obj.equal? other #=> false
obj.equal? obj #=> true
The #eql? method returns true
if +obj+ and +other+
refer to the same hash key. This is used by Hash to test members
for equality. For any pair of objects where #eql? returns +true+,
the #hash value of both objects must be equal. So any subclass
that overrides #eql? should also override #hash appropriately.
For objects of class Object, #eql? is synonymous
with #==. Subclasses normally continue this tradition by aliasing
#eql? to their overridden #== method, but there are exceptions.
Numeric types, for example, perform type conversion across #==,
but not across #eql?, so:
1 == 1.0 #=> true
1.eql? 1.0 #=> false;T;[o;=
;3I"
overload;F;40;;`;50;)I"==(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @o;=
;3I"
overload;F;40;;a;50;)I"equal?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @o;=
;3I"
overload;F;40;;_;50;)I"eql?(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[[I"
other;T0; @;[ ;@y;0; @;!F;"o;#;$T;%i;&i;6i ;'@;(I"}MJIT_FUNC_EXPORTED VALUE
rb_obj_equal(VALUE obj1, VALUE obj2)
{
if (obj1 == obj2) return Qtrue;
return Qfalse;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"BasicObject#!;F;[ ;[[@i;T;:!;0;[ ;{ ;IC;"Boolean negate.
;T;[o;=
;3I"
overload;F;40;;;50;)I" !obj;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @
;[ ;I"@return [Boolean];T;0; @
;!F;6i ;>0;[ ; @
;[ ;I":Boolean negate.
@overload !obj
@return [Boolean];T;0; @
;!F;"o;#;$T;%i;&i;'@;(I"_MJIT_FUNC_EXPORTED VALUE
rb_obj_not(VALUE obj)
{
return RTEST(obj) ? Qfalse : Qtrue;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"BasicObject#!=;F;[[I" obj2;T0;[[@i;T;:!=;0;[ ;{ ;IC;"@Returns true if two objects are not-equal, otherwise false.
;T;[o;=
;3I"
overload;F;40;;;50;)I"!=(other);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @(;[ ;I"@return [Boolean];T;0; @(;!F;6i ;>0;[[I"
other;T0; @(;[ ;I"kReturns true if two objects are not-equal, otherwise false.
@overload !=(other)
@return [Boolean];T;0; @(;!F;"o;#;$T;%i;&i;'@;(I"MJIT_FUNC_EXPORTED VALUE
rb_obj_not_equal(VALUE obj1, VALUE obj2)
{
VALUE result = rb_funcall(obj1, id_eq, 1, obj2);
return RTEST(result) ? Qfalse : Qtrue;
};T;)I"MJIT_FUNC_EXPORTED VALUE;T;*To;;F;
;;;;I"'BasicObject#singleton_method_added;F;[[I"_y;T0;[[@i;T;:singleton_method_added;0;[ ;{ ;IC;"call-seq:
singleton_method_added(symbol)
Invoked as a callback whenever a singleton method is added to the
receiver.
module Chatty
def Chatty.singleton_method_added(id)
puts "Adding #{id.id2name}"
end
def self.one() end
def two() end
def Chatty.three() end
end
produces:
Adding singleton_method_added
Adding one
Adding three
;T;[ ;[ ;I"
call-seq:
singleton_method_added(symbol)
Invoked as a callback whenever a singleton method is added to the
receiver.
module Chatty
def Chatty.singleton_method_added(id)
puts "Adding #{id.id2name}"
end
def self.one() end
def two() end
def Chatty.three() end
end
produces:
Adding singleton_method_added
Adding one
Adding three
;T;0; @G;!F;"o;#;$T;%i;&i;'@;(I"Rstatic VALUE
rb_obj_dummy1(VALUE _x, VALUE _y)
{
return rb_obj_dummy();
};T;)I"static VALUE;T;*To;;F;
;;;;I")BasicObject#singleton_method_removed;F;[[I"_y;T0;[[@i;T;:singleton_method_removed;0;[ ;{ ;IC;"call-seq:
singleton_method_removed(symbol)
Invoked as a callback whenever a singleton method is removed from
the receiver.
module Chatty
def Chatty.singleton_method_removed(id)
puts "Removing #{id.id2name}"
end
def self.one() end
def two() end
def Chatty.three() end
class << self
remove_method :three
remove_method :one
end
end
produces:
Removing three
Removing one
;T;[ ;[ ;I"
call-seq:
singleton_method_removed(symbol)
Invoked as a callback whenever a singleton method is removed from
the receiver.
module Chatty
def Chatty.singleton_method_removed(id)
puts "Removing #{id.id2name}"
end
def self.one() end
def two() end
def Chatty.three() end
class << self
remove_method :three
remove_method :one
end
end
produces:
Removing three
Removing one
;T;0; @W;!F;"o;#;$T;%i;&i;'@;(I"Rstatic VALUE
rb_obj_dummy1(VALUE _x, VALUE _y)
{
return rb_obj_dummy();
};T;)I"static VALUE;T;*To;;F;
;;;;I"+BasicObject#singleton_method_undefined;F;[[I"_y;T0;[[@i;T;:singleton_method_undefined;0;[ ;{ ;IC;"call-seq:
singleton_method_undefined(symbol)
Invoked as a callback whenever a singleton method is undefined in
the receiver.
module Chatty
def Chatty.singleton_method_undefined(id)
puts "Undefining #{id.id2name}"
end
def Chatty.one() end
class << self
undef_method(:one)
end
end
produces:
Undefining one
;T;[ ;[ ;I"
call-seq:
singleton_method_undefined(symbol)
Invoked as a callback whenever a singleton method is undefined in
the receiver.
module Chatty
def Chatty.singleton_method_undefined(id)
puts "Undefining #{id.id2name}"
end
def Chatty.one() end
class << self
undef_method(:one)
end
end
produces:
Undefining one
;T;0; @g;!F;"o;#;$T;%i;&i*;'@;(I"Rstatic VALUE
rb_obj_dummy1(VALUE _x, VALUE _y)
{
return rb_obj_dummy();
};T;)I"static VALUE;T;*To;;F;
;;;;I"BasicObject#instance_eval;F;[[@c0;[[@di;T;:instance_eval;0;[ ;{ ;IC;"Evaluates a string containing Ruby source code, or the given block,
within the context of the receiver (_obj_). In order to set the
context, the variable +self+ is set to _obj_ while
the code is executing, giving the code access to _obj_'s
instance variables and private methods.
When instance_eval
is given a block, _obj_ is also
passed in as the block's only argument.
When instance_eval
is given a +String+, the optional
second and third parameters supply a filename and starting line number
that are used when reporting compilation errors.
class KlassWithSecret
def initialize
@secret = 99
end
private
def the_secret
"Ssssh! The secret is #{@secret}."
end
end
k = KlassWithSecret.new
k.instance_eval { @secret } #=> 99
k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
k.instance_eval {|obj| obj == self } #=> true
;T;[o;=
;3I"
overload;F;40;;;50;)I"3instance_eval(string [, filename [, lineno]] );T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @w;[ ;I"@return [Object];T;0; @w;!F;6i ;>0;[[I""string[, filename [, lineno]];T0; @wo;=
;3I"
overload;F;40;;;50;)I"instance_eval;T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"obj;T; @wo;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @w;[ ;I""@yield [obj]
@return [Object];T;0; @w;!F;6i ;>0;[ ; @w;[ ;I"+Evaluates a string containing Ruby source code, or the given block,
within the context of the receiver (_obj_). In order to set the
context, the variable +self+ is set to _obj_ while
the code is executing, giving the code access to _obj_'s
instance variables and private methods.
When instance_eval
is given a block, _obj_ is also
passed in as the block's only argument.
When instance_eval
is given a +String+, the optional
second and third parameters supply a filename and starting line number
that are used when reporting compilation errors.
class KlassWithSecret
def initialize
@secret = 99
end
private
def the_secret
"Ssssh! The secret is #{@secret}."
end
end
k = KlassWithSecret.new
k.instance_eval { @secret } #=> 99
k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
k.instance_eval {|obj| obj == self } #=> true
@overload instance_eval(string [, filename [, lineno]] )
@return [Object]
@overload instance_eval
@yield [obj]
@return [Object];T;0; @w;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
rb_obj_instance_eval_internal(int argc, const VALUE *argv, VALUE self)
{
VALUE klass = singleton_class_for_eval(self);
return specific_eval(argc, argv, klass, self, RB_PASS_CALLED_KEYWORDS);
};T;)I"static VALUE;T;*To;;F;
;;;;I"BasicObject#instance_exec;F;[[@c0;[[@di;T;:instance_exec;0;[ ;{ ;IC;"Executes the given block within the context of the receiver
(_obj_). In order to set the context, the variable +self+ is set
to _obj_ while the code is executing, giving the code access to
_obj_'s instance variables. Arguments are passed as block parameters.
class KlassWithSecret
def initialize
@secret = 99
end
end
k = KlassWithSecret.new
k.instance_exec(5) {|x| @secret+x } #=> 104
;T;[o;=
;3I"
overload;F;40;;;50;)I"instance_exec(arg...);T;IC;" ;T;[o;2
;3I"
yield;F;4I" ;T;0;5[I"var...;T; @o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"%@yield [var...]
@return [Object];T;0; @;!F;6i ;>0;[[I"arg...;T0; @;[ ;I"Executes the given block within the context of the receiver
(_obj_). In order to set the context, the variable +self+ is set
to _obj_ while the code is executing, giving the code access to
_obj_'s instance variables. Arguments are passed as block parameters.
class KlassWithSecret
def initialize
@secret = 99
end
end
k = KlassWithSecret.new
k.instance_exec(5) {|x| @secret+x } #=> 104
@overload instance_exec(arg...)
@yield [var...]
@return [Object];T;0; @;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
rb_obj_instance_exec_internal(int argc, const VALUE *argv, VALUE self)
{
VALUE klass = singleton_class_for_eval(self);
return yield_under(klass, self, argc, argv, RB_PASS_CALLED_KEYWORDS);
};T;)I"static VALUE;T;*To;;F;
;;;;I"BasicObject#method_missing;F;[[@c0;[[@di;T;:method_missing;0;[ ;{ ;IC;"Invoked by Ruby when obj is sent a message it cannot handle.
symbol is the symbol for the method called, and args
are any arguments that were passed to it. By default, the interpreter
raises an error when this method is called. However, it is possible
to override the method to provide more dynamic behavior.
If it is decided that a particular method should not be handled, then
super should be called, so that ancestors can pick up the
missing method.
The example below creates
a class Roman
, which responds to methods with names
consisting of roman numerals, returning the corresponding integer
values.
class Roman
def roman_to_int(str)
# ...
end
def method_missing(symbol, *args)
str = symbol.id2name
begin
roman_to_int(str)
rescue
super(symbol, *args)
end
end
end
r = Roman.new
r.iv #=> 4
r.xxiii #=> 23
r.mm #=> 2000
r.foo #=> NoMethodError
;T;[o;=
;3I"
overload;F;40;;;50;)I"&method_missing(symbol [, *args] );T;IC;" ;T;[ ;[ ;I" ;T;0; @;!F;6i ;>0;[[I"symbol[, *args];T0; @;[ ;I"Invoked by Ruby when obj is sent a message it cannot handle.
symbol is the symbol for the method called, and args
are any arguments that were passed to it. By default, the interpreter
raises an error when this method is called. However, it is possible
to override the method to provide more dynamic behavior.
If it is decided that a particular method should not be handled, then
super should be called, so that ancestors can pick up the
missing method.
The example below creates
a class Roman
, which responds to methods with names
consisting of roman numerals, returning the corresponding integer
values.
class Roman
def roman_to_int(str)
# ...
end
def method_missing(symbol, *args)
str = symbol.id2name
begin
roman_to_int(str)
rescue
super(symbol, *args)
end
end
end
r = Roman.new
r.iv #=> 4
r.xxiii #=> 23
r.mm #=> 2000
r.foo #=> NoMethodError
@overload method_missing(symbol [, *args] );T;0; @;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
rb_method_missing(int argc, const VALUE *argv, VALUE obj)
{
rb_execution_context_t *ec = GET_EC();
raise_method_missing(ec, argc, argv, obj, ec->method_missing_reason);
UNREACHABLE_RETURN(Qnil);
};T;)I"static VALUE;T;*To;;F;
;;;;I"BasicObject#__send__;F;[[@c0;[[@di;T;;;0;[ ;{ ;IC;"Invokes the method identified by _symbol_, passing it any
arguments specified. You can use __send__
if the name
+send+ clashes with an existing method in _obj_.
When the method is identified by a string, the string is converted
to a symbol.
BasicObject implements +__send__+, Kernel implements +send+.
class Klass
def hello(*args)
"Hello " + args.join(' ')
end
end
k = Klass.new
k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
;T;[ o;=
;3I"
overload;F;40;;;50;)I"send(symbol [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol[, args...];T0; @o;=
;3I"
overload;F;40;;;50;)I"!__send__(symbol [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"symbol[, args...];T0; @o;=
;3I"
overload;F;40;;;50;)I"send(string [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string[, args...];T0; @o;=
;3I"
overload;F;40;;;50;)I"!__send__(string [, args...]);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Object;T; @;[ ;I"@return [Object];T;0; @;!F;6i ;>0;[[I"string[, args...];T0; @;[ ;@;0; @;!F;"o;#;$T;%i;&i;'@;(I"vVALUE
rb_f_send(int argc, VALUE *argv, VALUE recv)
{
return send_internal_kw(argc, argv, recv, CALL_FCALL);
};T;)I"
VALUE;T;*To;;F;
;;;;I"BasicObject#__id__;F;[ ;[[@
i;T;:__id__;0;[ ;{ ;IC;"4call-seq:
obj.__id__ -> integer
obj.object_id -> integer
Returns an integer identifier for +obj+.
The same number will be returned on all calls to +object_id+ for a given
object, and no two active objects will share an id.
Note: that some objects of builtin classes are reused for optimization.
This is the case for immediate values and frozen string literals.
BasicObject implements +__id__+, Kernel implements +object_id+.
Immediate values are not passed by reference but are passed by value:
+nil+, +true+, +false+, Fixnums, Symbols, and some Floats.
Object.new.object_id == Object.new.object_id # => false
(21 * 2).object_id == (21 * 2).object_id # => true
"hello".object_id == "hello".object_id # => false
"hi".freeze.object_id == "hi".freeze.object_id # => true
;T;[ ;[ ;@ ;0; @-;!F;"o;#;$T;%i;&i;'@;(I"VALUE
rb_obj_id(VALUE obj)
{
/*
* 32-bit VALUE space
* MSB ------------------------ LSB
* false 00000000000000000000000000000000
* true 00000000000000000000000000000010
* nil 00000000000000000000000000000100
* undef 00000000000000000000000000000110
* symbol ssssssssssssssssssssssss00001110
* object oooooooooooooooooooooooooooooo00 = 0 (mod sizeof(RVALUE))
* fixnum fffffffffffffffffffffffffffffff1
*
* object_id space
* LSB
* false 00000000000000000000000000000000
* true 00000000000000000000000000000010
* nil 00000000000000000000000000000100
* undef 00000000000000000000000000000110
* symbol 000SSSSSSSSSSSSSSSSSSSSSSSSSSS0 S...S % A = 4 (S...S = s...s * A + 4)
* object oooooooooooooooooooooooooooooo0 o...o % A = 0
* fixnum fffffffffffffffffffffffffffffff1 bignum if required
*
* where A = sizeof(RVALUE)/4
*
* sizeof(RVALUE) is
* 20 if 32-bit, double is 4-byte aligned
* 24 if 32-bit, double is 8-byte aligned
* 40 if 64-bit
*/
return rb_find_object_id(obj, cached_object_id);
};T;)I"
VALUE;T;*T;A@;BIC;[ ;A@;CIC;[ ;A@;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@i<[@i4[@i;T;:BasicObject;;K;;;[ ;{ ;IC;"BasicObject is the parent class of all classes in Ruby. It's an explicit
blank class.
BasicObject can be used for creating object hierarchies independent of
Ruby's object hierarchy, proxy objects like the Delegator class, or other
uses where namespace pollution from Ruby's methods and classes must be
avoided.
To avoid polluting BasicObject for other users an appropriately named
subclass of BasicObject should be created instead of directly modifying
BasicObject:
class MyObjectSystem < BasicObject
end
BasicObject does not include Kernel (for methods like +puts+) and
BasicObject is outside of the namespace of the standard library so common
classes will not be found without using a full class path.
A variety of strategies can be used to provide useful portions of the
standard library to subclasses of BasicObject. A subclass could
include Kernel
to obtain +puts+, +exit+, etc. A custom
Kernel-like module could be created and included or delegation can be used
via #method_missing:
class MyObjectSystem < BasicObject
DELEGATE = [:puts, :p]
def method_missing(name, *args, &block)
return super unless DELEGATE.include? name
::Kernel.send(name, *args, &block)
end
def respond_to_missing?(name, include_private = false)
DELEGATE.include?(name) or super
end
end
Access to classes and modules from the Ruby standard library can be
obtained in a BasicObject subclass by referencing the desired constant
from the root like ::File
or ::Enumerator
.
Like #method_missing, #const_missing can be used to delegate constant
lookup to +Object+:
class MyObjectSystem < BasicObject
def self.const_missing(name)
::Object.const_get(name)
end
end;T;[ ;[ ;I"
BasicObject is the parent class of all classes in Ruby. It's an explicit
blank class.
BasicObject can be used for creating object hierarchies independent of
Ruby's object hierarchy, proxy objects like the Delegator class, or other
uses where namespace pollution from Ruby's methods and classes must be
avoided.
To avoid polluting BasicObject for other users an appropriately named
subclass of BasicObject should be created instead of directly modifying
BasicObject:
class MyObjectSystem < BasicObject
end
BasicObject does not include Kernel (for methods like +puts+) and
BasicObject is outside of the namespace of the standard library so common
classes will not be found without using a full class path.
A variety of strategies can be used to provide useful portions of the
standard library to subclasses of BasicObject. A subclass could
include Kernel
to obtain +puts+, +exit+, etc. A custom
Kernel-like module could be created and included or delegation can be used
via #method_missing:
class MyObjectSystem < BasicObject
DELEGATE = [:puts, :p]
def method_missing(name, *args, &block)
return super unless DELEGATE.include? name
::Kernel.send(name, *args, &block)
end
def respond_to_missing?(name, include_private = false)
DELEGATE.include?(name) or super
end
end
Access to classes and modules from the Ruby standard library can be
obtained in a BasicObject subclass by referencing the desired constant
from the root like ::File
or ::Enumerator
.
Like #method_missing, #const_missing can be used to delegate constant
lookup to +Object+:
class MyObjectSystem < BasicObject
def self.const_missing(name)
::Object.const_get(name)
end
end
;T;0; @;!F;"o;#;$T;%i<;∈6i ;'@;I"BasicObject;F;So;L;M0;N0;O0;: Qnil;'@;Q0;R;F;R;Fo;
;IC;[
o;;F;
;F;;;I"Zlib::Deflate.deflate;F;[[@c0;[[@i;T;:deflate;0;[ ;{ ;IC;"call-seq:
Zlib.deflate(string[, level])
Zlib::Deflate.deflate(string[, level])
Compresses the given +string+. Valid values of level are
Zlib::NO_COMPRESSION, Zlib::BEST_SPEED, Zlib::BEST_COMPRESSION,
Zlib::DEFAULT_COMPRESSION, or an integer from 0 to 9.
This method is almost equivalent to the following code:
def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::FINISH)
z.close
dst
end
See also Zlib.inflate
;T;[ ;[ ;I"
call-seq:
Zlib.deflate(string[, level])
Zlib::Deflate.deflate(string[, level])
Compresses the given +string+. Valid values of level are
Zlib::NO_COMPRESSION, Zlib::BEST_SPEED, Zlib::BEST_COMPRESSION,
Zlib::DEFAULT_COMPRESSION, or an integer from 0 to 9.
This method is almost equivalent to the following code:
def deflate(string, level)
z = Zlib::Deflate.new(level)
dst = z.deflate(string, Zlib::FINISH)
z.close
dst
end
See also Zlib.inflate
;T;0; @P;!F;"o;#;$T;%i;&i;'@N;(I"&static VALUE
rb_deflate_s_deflate(int argc, VALUE *argv, VALUE klass)
{
struct zstream z;
VALUE src, level, dst, args[2];
int err, lev;
rb_scan_args(argc, argv, "11", &src, &level);
lev = ARG_LEVEL(level);
StringValue(src);
zstream_init_deflate(&z);
err = deflateInit(&z.stream, lev);
if (err != Z_OK) {
raise_zlib_error(err, z.stream.msg);
}
ZSTREAM_READY(&z);
args[0] = (VALUE)&z;
args[1] = src;
dst = rb_ensure(deflate_run, (VALUE)args, zstream_ensure_end, (VALUE)&z);
return dst;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Deflate#initialize;F;[[@c0;[[@iF;T;;;0;[ ;{ ;IC;"call-seq:
Zlib::Deflate.new(level=DEFAULT_COMPRESSION, window_bits=MAX_WBITS, mem_level=DEF_MEM_LEVEL, strategy=DEFAULT_STRATEGY)
Creates a new deflate stream for compression. If a given argument is nil,
the default value of that argument is used.
The +level+ sets the compression level for the deflate stream between 0 (no
compression) and 9 (best compression). The following constants have been
defined to make code more readable:
* Zlib::DEFAULT_COMPRESSION
* Zlib::NO_COMPRESSION
* Zlib::BEST_SPEED
* Zlib::BEST_COMPRESSION
See http://www.zlib.net/manual.html#Constants for further information.
The +window_bits+ sets the size of the history buffer and should be between
8 and 15. Larger values of this parameter result in better compression at
the expense of memory usage.
The +mem_level+ specifies how much memory should be allocated for the
internal compression state. 1 uses minimum memory but is slow and reduces
compression ratio while 9 uses maximum memory for optimal speed. The
default value is 8. Two constants are defined:
* Zlib::DEF_MEM_LEVEL
* Zlib::MAX_MEM_LEVEL
The +strategy+ sets the deflate compression strategy. The following
strategies are available:
Zlib::DEFAULT_STRATEGY:: For normal data
Zlib::FILTERED:: For data produced by a filter or predictor
Zlib::FIXED:: Prevents dynamic Huffman codes
Zlib::HUFFMAN_ONLY:: Prevents string matching
Zlib::RLE:: Designed for better compression of PNG image data
See the constants for further description.
== Examples
=== Basic
open "compressed.file", "w+" do |io|
io << Zlib::Deflate.new.deflate(File.read("big.file"))
end
=== Custom compression
open "compressed.file", "w+" do |compressed_io|
deflate = Zlib::Deflate.new(Zlib::BEST_COMPRESSION,
Zlib::MAX_WBITS,
Zlib::MAX_MEM_LEVEL,
Zlib::HUFFMAN_ONLY)
begin
open "big.file" do |big_io|
until big_io.eof? do
compressed_io << zd.deflate(big_io.read(16384))
end
end
ensure
deflate.close
end
end
While this example will work, for best optimization review the flags for
your specific time, memory usage and output space requirements.
;T;[ ;[ ;I"
call-seq:
Zlib::Deflate.new(level=DEFAULT_COMPRESSION, window_bits=MAX_WBITS, mem_level=DEF_MEM_LEVEL, strategy=DEFAULT_STRATEGY)
Creates a new deflate stream for compression. If a given argument is nil,
the default value of that argument is used.
The +level+ sets the compression level for the deflate stream between 0 (no
compression) and 9 (best compression). The following constants have been
defined to make code more readable:
* Zlib::DEFAULT_COMPRESSION
* Zlib::NO_COMPRESSION
* Zlib::BEST_SPEED
* Zlib::BEST_COMPRESSION
See http://www.zlib.net/manual.html#Constants for further information.
The +window_bits+ sets the size of the history buffer and should be between
8 and 15. Larger values of this parameter result in better compression at
the expense of memory usage.
The +mem_level+ specifies how much memory should be allocated for the
internal compression state. 1 uses minimum memory but is slow and reduces
compression ratio while 9 uses maximum memory for optimal speed. The
default value is 8. Two constants are defined:
* Zlib::DEF_MEM_LEVEL
* Zlib::MAX_MEM_LEVEL
The +strategy+ sets the deflate compression strategy. The following
strategies are available:
Zlib::DEFAULT_STRATEGY:: For normal data
Zlib::FILTERED:: For data produced by a filter or predictor
Zlib::FIXED:: Prevents dynamic Huffman codes
Zlib::HUFFMAN_ONLY:: Prevents string matching
Zlib::RLE:: Designed for better compression of PNG image data
See the constants for further description.
== Examples
=== Basic
open "compressed.file", "w+" do |io|
io << Zlib::Deflate.new.deflate(File.read("big.file"))
end
=== Custom compression
open "compressed.file", "w+" do |compressed_io|
deflate = Zlib::Deflate.new(Zlib::BEST_COMPRESSION,
Zlib::MAX_WBITS,
Zlib::MAX_MEM_LEVEL,
Zlib::HUFFMAN_ONLY)
begin
open "big.file" do |big_io|
until big_io.eof? do
compressed_io << zd.deflate(big_io.read(16384))
end
end
ensure
deflate.close
end
end
While this example will work, for best optimization review the flags for
your specific time, memory usage and output space requirements.
;T;0; @_;!F;"o;#;$T;%i;&iC;'@N;(I"+static VALUE
rb_deflate_initialize(int argc, VALUE *argv, VALUE obj)
{
struct zstream *z;
VALUE level, wbits, memlevel, strategy;
int err;
rb_scan_args(argc, argv, "04", &level, &wbits, &memlevel, &strategy);
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
err = deflateInit2(&z->stream, ARG_LEVEL(level), Z_DEFLATED,
ARG_WBITS(wbits), ARG_MEMLEVEL(memlevel),
ARG_STRATEGY(strategy));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
ZSTREAM_READY(z);
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I""Zlib::Deflate#initialize_copy;F;[[I" orig;T0;[[@i`;T;;j;0;[ ;{ ;IC;"#Duplicates the deflate stream.
;T;[ ;[ ;I"%
Duplicates the deflate stream.
;T;0; @n;!F;"o;#;$T;%i[;&i];'@N;(I"static VALUE
rb_deflate_init_copy(VALUE self, VALUE orig)
{
struct zstream *z1, *z2;
int err;
TypedData_Get_Struct(self, struct zstream, &zstream_data_type, z1);
z2 = get_zstream(orig);
if (z1 == z2) return self;
err = deflateCopy(&z1->stream, &z2->stream);
if (err != Z_OK) {
raise_zlib_error(err, 0);
}
z1->input = NIL_P(z2->input) ? Qnil : rb_str_dup(z2->input);
z1->buf = NIL_P(z2->buf) ? Qnil : rb_str_dup(z2->buf);
z1->flags = z2->flags;
return self;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Deflate#deflate;F;[[@c0;[[@i;T;;;0;[ ;{ ;IC;"ccall-seq:
z.deflate(string, flush = Zlib::NO_FLUSH) -> String
z.deflate(string, flush = Zlib::NO_FLUSH) { |chunk| ... } -> nil
Inputs +string+ into the deflate stream and returns the output from the
stream. On calling this method, both the input and the output buffers of
the stream are flushed. If +string+ is nil, this method finishes the
stream, just like Zlib::ZStream#finish.
If a block is given consecutive deflated chunks from the +string+ are
yielded to the block and +nil+ is returned.
The +flush+ parameter specifies the flush mode. The following constants
may be used:
Zlib::NO_FLUSH:: The default
Zlib::SYNC_FLUSH:: Flushes the output to a byte boundary
Zlib::FULL_FLUSH:: SYNC_FLUSH + resets the compression state
Zlib::FINISH:: Pending input is processed, pending output is flushed.
See the constants for further description.
;T;[ ;[ ;I"f
call-seq:
z.deflate(string, flush = Zlib::NO_FLUSH) -> String
z.deflate(string, flush = Zlib::NO_FLUSH) { |chunk| ... } -> nil
Inputs +string+ into the deflate stream and returns the output from the
stream. On calling this method, both the input and the output buffers of
the stream are flushed. If +string+ is nil, this method finishes the
stream, just like Zlib::ZStream#finish.
If a block is given consecutive deflated chunks from the +string+ are
yielded to the block and +nil+ is returned.
The +flush+ parameter specifies the flush mode. The following constants
may be used:
Zlib::NO_FLUSH:: The default
Zlib::SYNC_FLUSH:: Flushes the output to a byte boundary
Zlib::FULL_FLUSH:: SYNC_FLUSH + resets the compression state
Zlib::FINISH:: Pending input is processed, pending output is flushed.
See the constants for further description.
;T;0; @~;!F;"o;#;$T;%i;&i;'@N;(I"static VALUE
rb_deflate_deflate(int argc, VALUE *argv, VALUE obj)
{
struct zstream *z = get_zstream(obj);
VALUE src, flush;
rb_scan_args(argc, argv, "11", &src, &flush);
do_deflate(z, src, ARG_FLUSH(flush));
return zstream_detach_buffer(z);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Deflate#<<;F;[[I"src;T0;[[@i;T;:<<;0;[ ;{ ;IC;"call-seq: << string
Inputs +string+ into the deflate stream just like Zlib::Deflate#deflate, but
returns the Zlib::Deflate object itself. The output from the stream is
preserved in output buffer.
;T;[ ;[ ;I"
call-seq: << string
Inputs +string+ into the deflate stream just like Zlib::Deflate#deflate, but
returns the Zlib::Deflate object itself. The output from the stream is
preserved in output buffer.
;T;0; @;!F;"o;#;$T;%i;&i;'@N;(I"{static VALUE
rb_deflate_addstr(VALUE obj, VALUE src)
{
do_deflate(get_zstream(obj), src, Z_NO_FLUSH);
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Deflate#flush;F;[[@c0;[[@i;T;:
flush;0;[ ;{ ;IC;"call-seq:
flush(flush = Zlib::SYNC_FLUSH) -> String
flush(flush = Zlib::SYNC_FLUSH) { |chunk| ... } -> nil
This method is equivalent to deflate('', flush). This method is
just provided to improve the readability of your Ruby program. If a block
is given chunks of deflate output are yielded to the block until the buffer
is flushed.
See Zlib::Deflate#deflate for detail on the +flush+ constants NO_FLUSH,
SYNC_FLUSH, FULL_FLUSH and FINISH.
;T;[ ;[ ;I"
call-seq:
flush(flush = Zlib::SYNC_FLUSH) -> String
flush(flush = Zlib::SYNC_FLUSH) { |chunk| ... } -> nil
This method is equivalent to deflate('', flush). This method is
just provided to improve the readability of your Ruby program. If a block
is given chunks of deflate output are yielded to the block until the buffer
is flushed.
See Zlib::Deflate#deflate for detail on the +flush+ constants NO_FLUSH,
SYNC_FLUSH, FULL_FLUSH and FINISH.
;T;0; @;!F;"o;#;$T;%i;&i;'@N;(I"ystatic VALUE
rb_deflate_flush(int argc, VALUE *argv, VALUE obj)
{
struct zstream *z = get_zstream(obj);
VALUE v_flush;
int flush;
rb_scan_args(argc, argv, "01", &v_flush);
flush = FIXNUMARG(v_flush, Z_SYNC_FLUSH);
if (flush != Z_NO_FLUSH) { /* prevent Z_BUF_ERROR */
zstream_run(z, (Bytef*)"", 0, flush);
}
return zstream_detach_buffer(z);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Deflate#params;F;[[I"v_level;T0[I"v_strategy;T0;[[@i;T;:params;0;[ ;{ ;IC;".call-seq: params(level, strategy)
Changes the parameters of the deflate stream to allow changes between
different types of data that require different types of compression. Any
unprocessed data is flushed before changing the params.
See Zlib::Deflate.new for a description of +level+ and +strategy+.
;T;[ ;[ ;I"1
call-seq: params(level, strategy)
Changes the parameters of the deflate stream to allow changes between
different types of data that require different types of compression. Any
unprocessed data is flushed before changing the params.
See Zlib::Deflate.new for a description of +level+ and +strategy+.
;T;0; @;!F;"o;#;$T;%i;&i;'@N;(I"-static VALUE
rb_deflate_params(VALUE obj, VALUE v_level, VALUE v_strategy)
{
struct zstream *z = get_zstream(obj);
int level, strategy;
int err;
uInt n;
long filled;
level = ARG_LEVEL(v_level);
strategy = ARG_STRATEGY(v_strategy);
n = z->stream.avail_out;
err = deflateParams(&z->stream, level, strategy);
filled = n - z->stream.avail_out;
while (err == Z_BUF_ERROR) {
rb_warning("deflateParams() returned Z_BUF_ERROR");
zstream_expand_buffer(z);
rb_str_set_len(z->buf, RSTRING_LEN(z->buf) + filled);
n = z->stream.avail_out;
err = deflateParams(&z->stream, level, strategy);
filled = n - z->stream.avail_out;
}
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
rb_str_set_len(z->buf, RSTRING_LEN(z->buf) + filled);
return Qnil;
};T;)I"static VALUE;T;*To;;F;
;;;;I"!Zlib::Deflate#set_dictionary;F;[[I"dic;T0;[[@iJ;T;:set_dictionary;0;[ ;{ ;IC;"call-seq: set_dictionary(string)
Sets the preset dictionary and returns +string+. This method is available
just only after Zlib::Deflate.new or Zlib::ZStream#reset method was called.
See zlib.h for details.
Can raise errors of Z_STREAM_ERROR if a parameter is invalid (such as
NULL dictionary) or the stream state is inconsistent, Z_DATA_ERROR if
the given dictionary doesn't match the expected one (incorrect adler32 value)
;T;[ ;[ ;I"
call-seq: set_dictionary(string)
Sets the preset dictionary and returns +string+. This method is available
just only after Zlib::Deflate.new or Zlib::ZStream#reset method was called.
See zlib.h for details.
Can raise errors of Z_STREAM_ERROR if a parameter is invalid (such as
NULL dictionary) or the stream state is inconsistent, Z_DATA_ERROR if
the given dictionary doesn't match the expected one (incorrect adler32 value)
;T;0; @;!F;"o;#;$T;%i<;&iG;'@N;(I"]static VALUE
rb_deflate_set_dictionary(VALUE obj, VALUE dic)
{
struct zstream *z = get_zstream(obj);
VALUE src = dic;
int err;
StringValue(src);
err = deflateSetDictionary(&z->stream,
(Bytef*)RSTRING_PTR(src), RSTRING_LENINT(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
return dic;
};T;)I"static VALUE;T;*T;A@N;BIC;[ ;A@N;CIC;[ ;A@N;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@i[@i;T;:Deflate;;K;;;[ ;{ ;IC;"^Zlib::Deflate is the class for compressing data. See Zlib::ZStream for more
information.;T;[ ;[ ;I"`
Zlib::Deflate is the class for compressing data. See Zlib::ZStream for more
information.
;T;0; @N;!F;"o;#;$T;%i;&i;6i ;'o;L;M0;N0;O0;;P;'@;Q@;R0;I"Zlib::Deflate;F;S@
o;
;IC;[
o;;F;
;F;;;I"Zlib::Inflate.inflate;F;[[I"src;T0;[[@i;T;:inflate;0;[ ;{ ;IC;"call-seq:
Zlib.inflate(string)
Zlib::Inflate.inflate(string)
Decompresses +string+. Raises a Zlib::NeedDict exception if a preset
dictionary is needed for decompression.
This method is almost equivalent to the following code:
def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end
See also Zlib.deflate
;T;[ ;[ ;I"
call-seq:
Zlib.inflate(string)
Zlib::Inflate.inflate(string)
Decompresses +string+. Raises a Zlib::NeedDict exception if a preset
dictionary is needed for decompression.
This method is almost equivalent to the following code:
def inflate(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end
See also Zlib.deflate
;T;0; @;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
rb_inflate_s_inflate(VALUE obj, VALUE src)
{
struct zstream z;
VALUE dst, args[2];
int err;
StringValue(src);
zstream_init_inflate(&z);
err = inflateInit(&z.stream);
if (err != Z_OK) {
raise_zlib_error(err, z.stream.msg);
}
ZSTREAM_READY(&z);
args[0] = (VALUE)&z;
args[1] = src;
dst = rb_ensure(inflate_run, (VALUE)args, zstream_ensure_end, (VALUE)&z);
return dst;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Inflate#initialize;F;[[@c0;[[@i;T;;;0;[ ;{ ;IC;"call-seq:
Zlib::Inflate.new(window_bits = Zlib::MAX_WBITS)
Creates a new inflate stream for decompression. +window_bits+ sets the
size of the history buffer and can have the following values:
0::
Have inflate use the window size from the zlib header of the compressed
stream.
(8..15)::
Overrides the window size of the inflate header in the compressed stream.
The window size must be greater than or equal to the window size of the
compressed stream.
Greater than 15::
Add 32 to window_bits to enable zlib and gzip decoding with automatic
header detection, or add 16 to decode only the gzip format (a
Zlib::DataError will be raised for a non-gzip stream).
(-8..-15)::
Enables raw deflate mode which will not generate a check value, and will
not look for any check values for comparison at the end of the stream.
This is for use with other formats that use the deflate compressed data
format such as zip which provide their own check values.
== Example
open "compressed.file" do |compressed_io|
zi = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
begin
open "uncompressed.file", "w+" do |uncompressed_io|
uncompressed_io << zi.inflate(compressed_io.read)
end
ensure
zi.close
end
end
;T;[ ;[ ;I"
call-seq:
Zlib::Inflate.new(window_bits = Zlib::MAX_WBITS)
Creates a new inflate stream for decompression. +window_bits+ sets the
size of the history buffer and can have the following values:
0::
Have inflate use the window size from the zlib header of the compressed
stream.
(8..15)::
Overrides the window size of the inflate header in the compressed stream.
The window size must be greater than or equal to the window size of the
compressed stream.
Greater than 15::
Add 32 to window_bits to enable zlib and gzip decoding with automatic
header detection, or add 16 to decode only the gzip format (a
Zlib::DataError will be raised for a non-gzip stream).
(-8..-15)::
Enables raw deflate mode which will not generate a check value, and will
not look for any check values for comparison at the end of the stream.
This is for use with other formats that use the deflate compressed data
format such as zip which provide their own check values.
== Example
open "compressed.file" do |compressed_io|
zi = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
begin
open "uncompressed.file", "w+" do |uncompressed_io|
uncompressed_io << zi.inflate(compressed_io.read)
end
ensure
zi.close
end
end
;T;0; @;!F;"o;#;$T;%in;&i;'@;(I"static VALUE
rb_inflate_initialize(int argc, VALUE *argv, VALUE obj)
{
struct zstream *z;
VALUE wbits;
int err;
rb_scan_args(argc, argv, "01", &wbits);
TypedData_Get_Struct(obj, struct zstream, &zstream_data_type, z);
err = inflateInit2(&z->stream, ARG_WBITS(wbits));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
ZSTREAM_READY(z);
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"!Zlib::Inflate#add_dictionary;F;[[I"dictionary;T0;[[@i;T;:add_dictionary;0;[ ;{ ;IC;"call-seq: add_dictionary(string)
Provide the inflate stream with a dictionary that may be required in the
future. Multiple dictionaries may be provided. The inflate stream will
automatically choose the correct user-provided dictionary based on the
stream's required dictionary.
;T;[ ;[ ;I"
call-seq: add_dictionary(string)
Provide the inflate stream with a dictionary that may be required in the
future. Multiple dictionaries may be provided. The inflate stream will
automatically choose the correct user-provided dictionary based on the
stream's required dictionary.
;T;0; @;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
rb_inflate_add_dictionary(VALUE obj, VALUE dictionary)
{
VALUE dictionaries = rb_ivar_get(obj, id_dictionaries);
VALUE checksum = do_checksum(1, &dictionary, adler32);
rb_hash_aset(dictionaries, checksum, dictionary);
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Inflate#inflate;F;[[I"src;T0;[[@i,;T;;;0;[ ;{ ;IC;"$call-seq:
inflate(deflate_string) -> String
inflate(deflate_string) { |chunk| ... } -> nil
Inputs +deflate_string+ into the inflate stream and returns the output from
the stream. Calling this method, both the input and the output buffer of
the stream are flushed. If string is +nil+, this method finishes the
stream, just like Zlib::ZStream#finish.
If a block is given consecutive inflated chunks from the +deflate_string+
are yielded to the block and +nil+ is returned.
Raises a Zlib::NeedDict exception if a preset dictionary is needed to
decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
call this method again with an empty string to flush the stream:
inflater = Zlib::Inflate.new
begin
out = inflater.inflate compressed
rescue Zlib::NeedDict
# ensure the dictionary matches the stream's required dictionary
raise unless inflater.adler == Zlib.adler32(dictionary)
inflater.set_dictionary dictionary
inflater.inflate ''
end
# ...
inflater.close
See also Zlib::Inflate.new
;T;[ ;[ ;I"&
call-seq:
inflate(deflate_string) -> String
inflate(deflate_string) { |chunk| ... } -> nil
Inputs +deflate_string+ into the inflate stream and returns the output from
the stream. Calling this method, both the input and the output buffer of
the stream are flushed. If string is +nil+, this method finishes the
stream, just like Zlib::ZStream#finish.
If a block is given consecutive inflated chunks from the +deflate_string+
are yielded to the block and +nil+ is returned.
Raises a Zlib::NeedDict exception if a preset dictionary is needed to
decompress. Set the dictionary by Zlib::Inflate#set_dictionary and then
call this method again with an empty string to flush the stream:
inflater = Zlib::Inflate.new
begin
out = inflater.inflate compressed
rescue Zlib::NeedDict
# ensure the dictionary matches the stream's required dictionary
raise unless inflater.adler == Zlib.adler32(dictionary)
inflater.set_dictionary dictionary
inflater.inflate ''
end
# ...
inflater.close
See also Zlib::Inflate.new
;T;0; @;!F;"o;#;$T;%i;&i);'@;(I"static VALUE
rb_inflate_inflate(VALUE obj, VALUE src)
{
struct zstream *z = get_zstream(obj);
VALUE dst;
if (ZSTREAM_IS_FINISHED(z)) {
if (NIL_P(src)) {
dst = zstream_detach_buffer(z);
}
else {
StringValue(src);
zstream_append_buffer2(z, src);
dst = rb_str_new(0, 0);
}
}
else {
do_inflate(z, src);
dst = zstream_detach_buffer(z);
if (ZSTREAM_IS_FINISHED(z)) {
zstream_passthrough_input(z);
}
}
return dst;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Inflate#<<;F;[[I"src;T0;[[@iN;T;;;0;[ ;{ ;IC;"Inputs +string+ into the inflate stream just like Zlib::Inflate#inflate, but
returns the Zlib::Inflate object itself. The output from the stream is
preserved in output buffer.
;T;[o;=
;3I"
overload;F;40;;;50;)I"<< string;T;IC;" ;T;[ ;[ ;I" ;T;0; @";!F;6i ;>0;[[I"string;T0; @";[ ;I"Inputs +string+ into the inflate stream just like Zlib::Inflate#inflate, but
returns the Zlib::Inflate object itself. The output from the stream is
preserved in output buffer.
@overload << string;T;0; @";!F;"o;#;$T;%iG;&iL;'@;(I"Zstatic VALUE
rb_inflate_addstr(VALUE obj, VALUE src)
{
struct zstream *z = get_zstream(obj);
if (ZSTREAM_IS_FINISHED(z)) {
if (!NIL_P(src)) {
StringValue(src);
zstream_append_buffer2(z, src);
}
}
else {
do_inflate(z, src);
if (ZSTREAM_IS_FINISHED(z)) {
zstream_passthrough_input(z);
}
}
return obj;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Inflate#sync;F;[[I"src;T0;[[@ik;T;: sync;0;[ ;{ ;IC;"Inputs +string+ into the end of input buffer and skips data until a full
flush point can be found. If the point is found in the buffer, this method
flushes the buffer and returns false. Otherwise it returns +true+ and the
following data of full flush point is preserved in the buffer.
;T;[o;=
;3I"
overload;F;40;;;50;)I"sync(string);T;IC;" ;T;[ ;[ ;I" ;T;0; @<;!F;6i ;>0;[[I"string;T0; @<;[ ;I"7Inputs +string+ into the end of input buffer and skips data until a full
flush point can be found. If the point is found in the buffer, this method
flushes the buffer and returns false. Otherwise it returns +true+ and the
following data of full flush point is preserved in the buffer.
@overload sync(string);T;0; @<;!F;"o;#;$T;%ic;ⅈ'@;(I"static VALUE
rb_inflate_sync(VALUE obj, VALUE src)
{
struct zstream *z = get_zstream(obj);
StringValue(src);
return zstream_sync(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
};T;)I"static VALUE;T;*To;;F;
;;;;I"Zlib::Inflate#sync_point?;F;[ ;[[@i{;T;:sync_point?;0;[ ;{ ;IC;"OQuoted verbatim from original documentation:
What is this?
:);T;[o;2
;3I"return;F;4@|;0;5[@~; @V;[ ;I"PQuoted verbatim from original documentation:
What is this?
:)
;T;0; @V;!F;"o;#;$T;%it;&iy;6i ;'@;(I"static VALUE
rb_inflate_sync_point_p(VALUE obj)
{
struct zstream *z = get_zstream(obj);
int err;
err = inflateSyncPoint(&z->stream);
if (err == 1) {
return Qtrue;
}
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
return Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"!Zlib::Inflate#set_dictionary;F;[[I"dic;T0;[[@i;T;;;0;[ ;{ ;IC;"Sets the preset dictionary and returns +string+. This method is available just
only after a Zlib::NeedDict exception was raised. See zlib.h for details.
;T;[ ;[ ;I"
Sets the preset dictionary and returns +string+. This method is available just
only after a Zlib::NeedDict exception was raised. See zlib.h for details.
;T;0; @g;!F;"o;#;$T;%i;&i;'@;(I"]static VALUE
rb_inflate_set_dictionary(VALUE obj, VALUE dic)
{
struct zstream *z = get_zstream(obj);
VALUE src = dic;
int err;
StringValue(src);
err = inflateSetDictionary(&z->stream,
(Bytef*)RSTRING_PTR(src), RSTRING_LENINT(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
return dic;
};T;)I"static VALUE;T;*T;A@;BIC;[ ;A@;CIC;[ ;A@;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@i^[@i;T;:Inflate;;K;;;[ ;{ ;IC;"Zlib:Inflate is the class for decompressing compressed data. Unlike
Zlib::Deflate, an instance of this class is not able to duplicate (clone,
dup) itself.;T;[ ;[ ;I"
Zlib:Inflate is the class for decompressing compressed data. Unlike
Zlib::Deflate, an instance of this class is not able to duplicate (clone,
dup) itself.
;T;0; @;!F;"o;#;$T;%i^;&ib;6i ;'o;L;M0;N0;O0;;P;'@;Q@;R0;I"Zlib::Inflate;F;S@
o;
;IC;[o;
;IC;[o;;F;
;;;;I" Zlib::GzipFile::Error#input;F;[ ;[[@ic;F;:
input;;K;[ ;{ ;IC;"input gzipped string
;T;[ ;[ ;I"input gzipped string;T;0; @;!F;"o;#;$T;%ib;&ib;'@;*To;;F;
;;;;I""Zlib::GzipFile::Error#inspect;F;[ ;[[@i ;T;;v;0;[ ;{ ;IC;".Constructs a String of the GzipFile Error
;T;[ ;[ ;I"0
Constructs a String of the GzipFile Error
;T;0; @;!F;"o;#;$T;%i ;&i ;'@;(I"Cstatic VALUE
gzfile_error_inspect(VALUE error)
{
VALUE str = rb_call_super(0, 0);
VALUE input = rb_attr_get(error, id_input);
if (!NIL_P(input)) {
rb_str_resize(str, RSTRING_LEN(str)-1);
rb_str_cat2(str, ", input=");
rb_str_append(str, rb_str_inspect(input));
rb_str_cat2(str, ">");
}
return str;
};T;)I"static VALUE;T;*T;A@;BIC;[ ;A@;CIC;[ ;A@;DIC;E{;FIC;E{ ;GT;IC;E{;IC;E{: read@:
write0;GT;GT;GT;H{ ;I[ ;[[@i?[@i`;T;:
Error;;K;;;[ ;{ ;IC;"@Base class of errors that occur when processing GZIP files.
;T;[ ;[ ;I"B
Base class of errors that occur when processing GZIP files.
;T;0; @;!F;"o;#;$T;%i?;&iA;'@;I"Zlib::GzipFile::Error;F;So;
;IC;[ ;A@;BIC;[ ;A@;CIC;[ ;A@;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[@i[@i;T;;;;K;;;[ ;{ ;IC;"hThe superclass for all exceptions raised by Ruby/zlib.
The following exceptions are defined as subclasses of Zlib::Error. These
exceptions are raised when zlib library functions return with an error
status.
- Zlib::StreamEnd
- Zlib::NeedDict
- Zlib::DataError
- Zlib::StreamError
- Zlib::MemError
- Zlib::BufError
- Zlib::VersionError
- Zlib::InProgressError
;T;[ ;[ ;I"k
The superclass for all exceptions raised by Ruby/zlib.
The following exceptions are defined as subclasses of Zlib::Error. These
exceptions are raised when zlib library functions return with an error
status.
- Zlib::StreamEnd
- Zlib::NeedDict
- Zlib::DataError
- Zlib::StreamError
- Zlib::MemError
- Zlib::BufError
- Zlib::VersionError
- Zlib::InProgressError
;T;0; @;!F;"o;#;$T;%i;&i;'@;I"Zlib::Error;F;So;L;M0;N0;O0;:StandardError;'@;Qo;
;IC;[ ;A@;BIC;[ ;A@;CIC;[ ;A@;DIC;E{;FIC;E{ ;GT;IC;E{ ;GT;GT;H{ ;I[ ;[[I"error.c;Tid[@i
;T;;;;K;;;[ ;{ ;IC;"The most standard error types are subclasses of StandardError. A
rescue clause without an explicit Exception class will rescue all
StandardErrors (and only those).
def foo
raise "Oups"
end
foo rescue "Hello" #=> "Hello"
On the other hand:
require 'does/not/exist' rescue "Hi"
raises the exception:
LoadError: no such file to load -- does/not/exist
;T;[ ;[ ;I"
The most standard error types are subclasses of StandardError. A
rescue clause without an explicit Exception class will rescue all
StandardErrors (and only those).
def foo
raise "Oups"
end
foo rescue "Hello" #=> "Hello"
On the other hand:
require 'does/not/exist' rescue "Hi"
raises the exception:
LoadError: no such file to load -- does/not/exist
;T;0; @;!F;"o;#;$T;%id;&iv;'@;I"StandardError;F;So;
;IC;[o;;F;
;F;;;I"Exception.exception;F;[[@c0;[[@i;T;:exception;0;[ ;{ ;IC;"DAllocates and initializes an instance of \a klass.
Equivalent to \c Class\#new in Ruby
\param[in] argc the number of arguments to \c #initialize
\param[in] argv a pointer to an array of arguments to \c #initialize
\param[in] klass a Class object
\return the new instance of \a klass
\sa rb_obj_call_init
\sa rb_obj_alloc
;T;[ ;[ ;I"EAllocates and initializes an instance of \a klass.
Equivalent to \c Class\#new in Ruby
\param[in] argc the number of arguments to \c #initialize
\param[in] argv a pointer to an array of arguments to \c #initialize
\param[in] klass a Class object
\return the new instance of \a klass
\sa rb_obj_call_init
\sa rb_obj_alloc
;T;0; @;!F;"o;#;$T;%iy;&i;'@;(I"VALUE
rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
{
VALUE obj;
Check_Type(klass, T_CLASS);
obj = rb_class_alloc(klass);
rb_obj_call_init_kw(obj, argc, argv, RB_NO_KEYWORDS);
return obj;
};T;)I"
VALUE;T;*To;;F;
;F;;;I"Exception.to_tty?;F;[ ;[[@i+;T;:to_tty?;0;[ ;{ ;IC;"@Returns +true+ if exception messages will be sent to a tty.;T;[o;=
;3I"
overload;F;40;;;50;)I"to_tty?;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @;[ ;I"@return [Boolean];T;0; @;!F;6i ;>0;[ ; @;[ ;I"hReturns +true+ if exception messages will be sent to a tty.
@overload to_tty?
@return [Boolean];T;0; @;!F;"o;#;$T;%i%;&i);6i ;'@;(I"_static VALUE
exc_s_to_tty_p(VALUE self)
{
return rb_stderr_tty_p() ? Qtrue : Qfalse;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#exception;F;[[@c0;[[@i;T;;;0;[ ;{ ;IC;"call-seq:
exc.exception(string) -> an_exception or exc
With no argument, or if the argument is the same as the receiver,
return the receiver. Otherwise, create a new
exception object of the same class as the receiver, but with a
message equal to string.to_str
.
;T;[ ;[ ;I"
call-seq:
exc.exception(string) -> an_exception or exc
With no argument, or if the argument is the same as the receiver,
return the receiver. Otherwise, create a new
exception object of the same class as the receiver, but with a
message equal to string.to_str
.
;T;0; @;!F;"o;#;$T;%i;&i;'@;(I"!static VALUE
exc_exception(int argc, VALUE *argv, VALUE self)
{
VALUE exc;
argc = rb_check_arity(argc, 0, 1);
if (argc == 0) return self;
if (argc == 1 && self == argv[0]) return self;
exc = rb_obj_clone(self);
rb_ivar_set(exc, id_mesg, argv[0]);
return exc;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#initialize;F;[[@c0;[[@i;T;;;0;[ ;{ ;IC;"HConstruct a new Exception object, optionally passing in
a message.
;T;[o;=
;3I"
overload;F;40;:new;50;)I"new(msg = nil);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Exception;T; @ ;[ ;I"@return [Exception];T;0; @ ;!F;6i ;>0;[[I"msg;TI"nil;T; @ ;[ ;I"z Construct a new Exception object, optionally passing in
a message.
@overload new(msg = nil)
@return [Exception];T;0; @ ;!F;"o;#;$T;%i;&i;'@;(I"static VALUE
exc_initialize(int argc, VALUE *argv, VALUE exc)
{
VALUE arg;
arg = (!rb_check_arity(argc, 0, 1) ? Qnil : argv[0]);
return exc_init(exc, arg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#==;F;[[I"obj;T0;[[@iC;T;;`;0;[ ;{ ;IC;"Equality---If obj is not an Exception, returns
false
. Otherwise, returns true
if exc and
obj share same class, messages, and backtrace.
;T;[o;=
;3I"
overload;F;40;;`;50;)I"==(obj);T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"Boolean;T; @?;[ ;I"@return [Boolean];T;0; @?;!F;6i ;>0;[[I"obj;T0; @?;[ ;I"Equality---If obj is not an Exception, returns
false
. Otherwise, returns true
if exc and
obj share same class, messages, and backtrace.
@overload ==(obj)
@return [Boolean];T;0; @?;!F;"o;#;$T;%i:;&i@;'@;(I"static VALUE
exc_equal(VALUE exc, VALUE obj)
{
VALUE mesg, backtrace;
if (exc == obj) return Qtrue;
if (rb_obj_class(exc) != rb_obj_class(obj)) {
int state;
obj = rb_protect(try_convert_to_exception, obj, &state);
if (state || obj == Qundef) {
rb_set_errinfo(Qnil);
return Qfalse;
}
if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
mesg = rb_check_funcall(obj, id_message, 0, 0);
if (mesg == Qundef) return Qfalse;
backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
if (backtrace == Qundef) return Qfalse;
}
else {
mesg = rb_attr_get(obj, id_mesg);
backtrace = exc_backtrace(obj);
}
if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
return Qfalse;
if (!rb_equal(exc_backtrace(exc), backtrace))
return Qfalse;
return Qtrue;
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#to_s;F;[ ;[[@i;T;;u;0;[ ;{ ;IC;"UReturns exception's message (or the name of the exception if
no message is set).
;T;[o;=
;3I"
overload;F;40;;u;50;)I" to_s;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @^;[ ;I"@return [String];T;0; @^;!F;6i ;>0;[ ; @^;[ ;I"yReturns exception's message (or the name of the exception if
no message is set).
@overload to_s
@return [String];T;0; @^;!F;"o;#;$T;%i;&i
;'@;(I"static VALUE
exc_to_s(VALUE exc)
{
VALUE mesg = rb_attr_get(exc, idMesg);
if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
return rb_String(mesg);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#message;F;[ ;[[@ix;T;:message;0;[ ;{ ;IC;"wReturns the result of invoking exception.to_s
.
Normally this returns the exception's message or name.
;T;[o;=
;3I"
overload;F;40;;;50;)I"message;T;IC;" ;T;[o;2
;3I"return;F;4I" ;T;0;5[I"String;T; @y;[ ;I"@return [String];T;0; @y;!F;6i ;>0;[ ; @y;[ ;I"Returns the result of invoking exception.to_s
.
Normally this returns the exception's message or name.
@overload message
@return [String];T;0; @y;!F;"o;#;$T;%ip;&iu;'@;(I"Wstatic VALUE
exc_message(VALUE exc)
{
return rb_funcallv(exc, idTo_s, 0, 0);
};T;)I"static VALUE;T;*To;;F;
;;;;I"Exception#full_message;F;[[@c0;[[@iC;T;:full_message;0;[ ;{ ;IC;"Returns formatted string of _exception_.
The returned string is formatted using the same format that Ruby uses
when printing an uncaught exceptions to stderr.
If _highlight_ is +true+ the default error handler will send the
messages to a tty.
_order_ must be either of +:top+ or +:bottom+, and places the error
message and the innermost backtrace come at the top or the bottom.
The default values of these options depend on $stderr
and its +tty?+ at the timing of a call.
;T;[o;=
;3I"
overload;F;40;;;50;)I"