method
inspect
Related methods
- Class methods (3)
-
new
-
try_convert
(>= v1_9_1_378)
-
yaml_new
- Instance methods (148)
-
<<
-
<=>
-
=~
-
==
-
===
(>= v1_9_1_378)
-
[]
-
[]=
-
*
-
%
-
+
-
ascii_only?
(>= v1_9_1_378)
-
block_scanf
-
bytes
(>= v1_8_7_72)
-
bytesize
(>= v1_8_7_72)
-
byteslice
(>= v1_9_3_125)
-
capitalize
-
capitalize!
-
casecmp
-
center
-
chars
(>= v1_8_7_72)
-
chomp
-
chomp!
-
chop
-
chop!
-
chr
(>= v1_9_1_378)
-
clear
(>= v1_9_1_378)
-
codepoints
(>= v1_9_1_378)
-
concat
-
count
-
crypt
-
delete
-
delete!
-
downcase
-
downcase!
-
dump
-
each
-
each_byte
-
each_char
-
each_codepoint
(>= v1_9_1_378)
-
each_line
-
empty?
-
encode
(>= v1_9_1_378)
-
encode!
(>= v1_9_1_378)
-
encoding
(>= v1_9_1_378)
-
end_regexp
-
end_with?
(>= v1_8_7_72)
-
eql?
-
_expand_ch
-
expand_ch_hash
-
ext
(>= v1_9_3_125)
-
force_encoding
(>= v1_9_1_378)
-
getbyte
(>= v1_9_1_378)
-
gsub
-
gsub!
-
hash
-
hex
-
include?
-
index
-
initialize_copy
-
insert
-
inspect
-
intern
-
is_binary_data?
-
is_complex_yaml?
-
iseuc
-
isjis
(>= v1_9_1_378)
-
issjis
-
isutf8
-
jcount
-
jlength
-
jsize
-
kconv
-
length
-
lines
(>= v1_8_7_72)
-
ljust
-
lstrip
-
lstrip!
-
match
-
mbchar?
-
next
-
next!
-
oct
-
ord
(>= v1_9_1_378)
-
original_succ
-
original_succ!
-
parse_csv
(>= v1_9_1_378)
-
partition
(>= v1_8_7_72)
-
pathmap
(>= v1_9_3_125)
-
pathmap_explode
(>= v1_9_3_125)
-
pathmap_partial
(>= v1_9_3_125)
-
pathmap_replace
(>= v1_9_3_125)
-
prepend
(>= v1_9_3_125)
-
quote
-
_regex_quote
-
replace
-
reverse
-
reverse!
-
rindex
-
rjust
-
rpartition
(>= v1_8_7_72)
-
rstrip
-
rstrip!
-
scan
-
scanf
-
setbyte
(>= v1_9_1_378)
-
shellescape
(>= v1_8_7_72)
-
shellsplit
(>= v1_8_7_72)
-
size
-
slice
-
slice!
-
split
-
squeeze
-
squeeze!
-
start_with?
(>= v1_8_7_72)
-
strip
-
strip!
-
sub
-
sub!
-
succ
-
succ!
-
sum
-
swapcase
-
swapcase!
-
to_c
(>= v1_9_1_378)
-
to_d
(>= v1_9_1_378)
-
toeuc
-
to_f
-
to_i
-
tojis
-
tolocale
(>= v1_9_1_378)
-
to_r
(>= v1_9_1_378)
-
to_s
-
tosjis
-
to_str
-
to_sym
-
toutf16
-
toutf32
(>= v1_9_1_378)
-
toutf8
-
to_yaml
-
tr
-
tr!
-
tr_s
-
tr_s!
-
unpack
-
upcase
-
upcase!
-
upto
-
valid_encoding?
(>= v1_9_1_378)
= private
= protected
inspect()
public
Returns a printable version of str, with special characters escaped.
str = "hello" str[3] = 8 str.inspect #=> "hel\010o"
Show source
/* * call-seq: * str.inspect => string * * Returns a printable version of _str_, with special characters * escaped. * * str = "hello" * str[3] = 8 * str.inspect #=> "hel\010o" */ VALUE rb_str_inspect(str) VALUE str; { char *p, *pend; VALUE result = rb_str_buf_new2("\""); char s[5]; p = RSTRING(str)->ptr; pend = p + RSTRING(str)->len; while (p < pend) { char c = *p++; if (ismbchar(c) && p < pend) { int len = mbclen(c); rb_str_buf_cat(result, p - 1, len); p += len - 1; } else if (c == '"'|| c == '\\' || (c == '#' && IS_EVSTR(p, pend))) { s[0] = '\\'; s[1] = c; rb_str_buf_cat(result, s, 2); } else if (ISPRINT(c)) { s[0] = c; rb_str_buf_cat(result, s, 1); } else if (c == '\n') { s[0] = '\\'; s[1] = 'n'; rb_str_buf_cat(result, s, 2); } else if (c == '\r') { s[0] = '\\'; s[1] = 'r'; rb_str_buf_cat(result, s, 2); } else if (c == '\t') { s[0] = '\\'; s[1] = 't'; rb_str_buf_cat(result, s, 2); } else if (c == '\f') { s[0] = '\\'; s[1] = 'f'; rb_str_buf_cat(result, s, 2); } else if (c == '\013') { s[0] = '\\'; s[1] = 'v'; rb_str_buf_cat(result, s, 2); } else if (c == '\010') { s[0] = '\\'; s[1] = 'b'; rb_str_buf_cat(result, s, 2); } else if (c == '\007') { s[0] = '\\'; s[1] = 'a'; rb_str_buf_cat(result, s, 2); } else if (c == 033) { s[0] = '\\'; s[1] = 'e'; rb_str_buf_cat(result, s, 2); } else { sprintf(s, "\\%03o", c & 0377); rb_str_buf_cat2(result, s); } } rb_str_buf_cat2(result, "\""); OBJ_INFECT(result, str); return result; }


