ÿØÿà JFIF ÿÛ „ ( %!1!%)+//.383,7(-.+
-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ ¥2" ÿÄ ÿÄ J ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ ÿÄ * !1AQa‘"2q3±ð#b¡ÿÚ ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁTÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßwpŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
?>
.........................................
.............................................................................
ÿØÿà JFIF ÿÛ „
(
%!1!%)+//.383,7(-.+
-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ ¥2" ÿÄ
ÿÄ J ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ
ÿÄ * !1AQa‘"2q3±ð#b¡ÿÚ
? ¼QxJQaÍuò¸Zö
Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁTÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßwpŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
?>
.........................................
.............................................................................
????????????????????????????????????
????????????????????????????????????
ÿØÿà JFIF ÿÛ „ ( %!1!%)+//.383,7(-.+
-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ ¥2" ÿÄ ÿÄ J ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ ÿÄ * !1AQa‘"2q3±ð#b¡ÿÚ ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁTÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßwpŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
?>
.........................................
.............................................................................
ÿØÿà JFIF ÿÛ „
(
%!1!%)+//.383,7(-.+
-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ ¥2" ÿÄ
ÿÄ J ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ
ÿÄ * !1AQa‘"2q3±ð#b¡ÿÚ
? ¼QxJQaÍuò¸Zö
Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁTÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßwpŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
?>
.........................................
.............................................................................
????????????????????????????????????
????????????????????????????????????
U:RDoc::TopLevel[ i I"implicit_conversion.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[aS:RDoc::Markup::Heading:
leveli: textI"Implicit Conversions;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I"2Some Ruby methods accept one or more objects ;TI"that can be either:;T@
o:RDoc::Markup::List:
@type:BULLET:@items[o:RDoc::Markup::ListItem:@label0;[o;
;[I"4Of a given class, and so accepted as is.;To;;0;[o;
;[I"@Implicitly convertible to that class, in which case ;TI"+the called method converts the object.;T@
o;
;[I"IFor each of the relevant classes, the conversion is done by calling ;TI""a specific conversion method:;T@
o;;;;[ o;;0;[o;
;[I"Array: +to_ary+;To;;0;[o;
;[I"Hash: +to_hash+;To;;0;[o;
;[I"Integer: +to_int+;To;;0;[o;
;[I"String: +to_str+;T@
S; ;
i;I"Array-Convertible Objects;T@
o;
;[I":An Array-convertible object is an object that:;T@
o;;;;[o;;0;[o;
;[I""Has instance method +to_ary+.;To;;0;[o;
;[I"%The method accepts no arguments.;To;;0;[o;
;[I"^The method returns an object +obj+ for which obj.kind_of?(Array) returns +true+.;T@
o;
;[I">The Ruby core class that satisfies these requirements is:;T@
o;;;;[o;;0;[o;
;[I"
Array;T@
o;
;[I"EThe examples in this section use method Array#replace, ;TI"1which accepts an Array-convertible argument.;T@
o;
;[I"%This class is Array-convertible:;T@
o:RDoc::Markup::Verbatim;[I"class ArrayConvertible
;TI" def to_ary
;TI" [:foo, 'bar', 2]
;TI" end
;TI" end
;TI"a = []
;TI";a.replace(ArrayConvertible.new) # => [:foo, "bar", 2]
;T:@format0o;
;[I">This class is not Array-convertible (no +to_ary+ method):;T@
o;;[ I"$class NotArrayConvertible; end
;TI"a = []
;TI"S# Raises TypeError (no implicit conversion of NotArrayConvertible into Array)
;TI"(a.replace(NotArrayConvertible.new)
;T;0o;
;[I"KThis class is not Array-convertible (method +to_ary+ takes arguments):;T@
o;;[
I"class NotArrayConvertible
;TI" def to_ary(x)
;TI" [:foo, 'bar', 2]
;TI" end
;TI" end
;TI"a = []
;TI"N# Raises ArgumentError (wrong number of arguments (given 0, expected 1))
;TI"(a.replace(NotArrayConvertible.new)
;T;0o;
;[I"MThis class is not Array-convertible (method +to_ary+ returns non-Array):;T@
o;;[
I"class NotArrayConvertible
;TI" def to_ary
;TI" :foo
;TI" end
;TI" end
;TI"a = []
;TI"o# Raises TypeError (can't convert NotArrayConvertible to Array (NotArrayConvertible#to_ary gives Symbol))
;TI"(a.replace(NotArrayConvertible.new)
;T;0S; ;
i;I"Hash-Convertible Objects;T@
o;
;[I"8A Hash-convertible object is an object that:;T@
o;;;;[o;;0;[o;
;[I"#Has instance method +to_hash+.;To;;0;[o;
;[I"%The method accepts no arguments.;To;;0;[o;
;[I"]The method returns an object +obj+ for which obj.kind_of?(Hash) returns +true+.;T@
o;
;[I">The Ruby core class that satisfies these requirements is:;T@
o;;;;[o;;0;[o;
;[I" Hash;T@
o;
;[I"BThe examples in this section use method Hash#merge, ;TI"/which accepts a Hash-convertible argument.;T@
o;
;[I"$This class is Hash-convertible:;T@
o;;[I"class HashConvertible
;TI" def to_hash
;TI"" {foo: 0, bar: 1, baz: 2}
;TI" end
;TI" end
;TI"h = {}
;TI"Ch.merge(HashConvertible.new) # => {:foo=>0, :bar=>1, :baz=>2}
;T;0o;
;[I">This class is not Hash-convertible (no +to_hash+ method):;T@
o;;[ I"#class NotHashConvertible; end
;TI"h = {}
;TI"Q# Raises TypeError (no implicit conversion of NotHashConvertible into Hash)
;TI"%h.merge(NotHashConvertible.new)
;T;0o;
;[I"KThis class is not Hash-convertible (method +to_hash+ takes arguments):;T@
o;;[
I"class NotHashConvertible
;TI" def to_hash(x)
;TI"" {foo: 0, bar: 1, baz: 2}
;TI" end
;TI" end
;TI"h = {}
;TI"N# Raises ArgumentError (wrong number of arguments (given 0, expected 1))
;TI"%h.merge(NotHashConvertible.new)
;T;0o;
;[I"LThis class is not Hash-convertible (method +to_hash+ returns non-Hash):;T@
o;;[
I"class NotHashConvertible
;TI" def to_hash
;TI" :foo
;TI" end
;TI" end
;TI"h = {}
;TI"o# Raises TypeError (can't convert NotHashConvertible to Hash (ToHashReturnsNonHash#to_hash gives Symbol))
;TI"%h.merge(NotHashConvertible.new)
;T;0S; ;
i;I" Integer-Convertible Objects;T@
o;
;[I"Integer-convertible object is an object that:;T@
o;;;;[o;;0;[o;
;[I""Has instance method +to_int+.;To;;0;[o;
;[I"%The method accepts no arguments.;To;;0;[o;
;[I"`The method returns an object +obj+ for which obj.kind_of?(Integer) returns +true+.;T@
o;
;[I"?The Ruby core classes that satisfy these requirements are:;T@
o;;;;[ o;;0;[o;
;[I"Integer;To;;0;[o;
;[I"
Float;To;;0;[o;
;[I"Complex;To;;0;[o;
;[I"
Rational;T@
o;
;[I"AThe examples in this section use method Array.new, ;TI"3which accepts an Integer-convertible argument.;T@
o;
;[I"4This user-defined class is Integer-convertible:;T@
o;;[I"class IntegerConvertible
;TI" def to_int
;TI" 3
;TI" end
;TI" end
;TI"0a = Array.new(IntegerConvertible.new).size
;TI"a # => 3
;T;0o;
;[I"MThis class is not Integer-convertible (method +to_int+ takes arguments):;T@
o;;[I"!class NotIntegerConvertible
;TI" def to_int(x)
;TI" 3
;TI" end
;TI" end
;TI"N# Raises ArgumentError (wrong number of arguments (given 0, expected 1))
;TI"*Array.new(NotIntegerConvertible.new)
;T;0o;
;[I"QThis class is not Integer-convertible (method +to_int+ returns non-Integer):;T@
o;;[I"!class NotIntegerConvertible
;TI" def to_int
;TI" :foo
;TI" end
;TI" end
;TI"u# Raises TypeError (can't convert NotIntegerConvertible to Integer (NotIntegerConvertible#to_int gives Symbol))
;TI"*Array.new(NotIntegerConvertible.new)
;T;0S; ;
i;I"String-Convertible Objects;T@
o;
;[I":A String-convertible object is an object that:;To;;;;[o;;0;[o;
;[I""Has instance method +to_str+.;To;;0;[o;
;[I"%The method accepts no arguments.;To;;0;[o;
;[I"_The method returns an object +obj+ for which obj.kind_of?(String) returns +true+.;T@
o;
;[I">The Ruby core class that satisfies these requirements is:;T@
o;;;;[o;;0;[o;
;[I"String;T@
o;
;[I"CThe examples in this section use method String::new, ;TI"1which accepts a String-convertible argument.;T@
o;
;[I"&This class is String-convertible:;T@
o;;[I"class StringConvertible
;TI" def to_str
;TI" 'foo'
;TI" end
;TI" end
;TI"2String.new(StringConvertible.new) # => "foo"
;T;0o;
;[I"?This class is not String-convertible (no +to_str+ method):;T@
o;;[I"%class NotStringConvertible; end
;TI"U# Raises TypeError (no implicit conversion of NotStringConvertible into String)
;TI"*String.new(NotStringConvertible.new)
;T;0o;
;[I"LThis class is not String-convertible (method +to_str+ takes arguments):;T@
o;;[I" class NotStringConvertible
;TI" def to_str(x)
;TI" 'foo'
;TI" end
;TI" end
;TI"N# Raises ArgumentError (wrong number of arguments (given 0, expected 1))
;TI"*String.new(NotStringConvertible.new)
;T;0o;
;[I"OThis class is not String-convertible (method +to_str+ returns non-String):;T@
o;;[I" class NotStringConvertible
;TI" def to_str
;TI" :foo
;TI" end
;TI" end
;TI"r# Raises TypeError (can't convert NotStringConvertible to String (NotStringConvertible#to_str gives Symbol))
;TI")String.new(NotStringConvertible.new);T;0:
@file@:0@omit_headings_from_table_of_contents_below0