1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[DOC] Use unpack1 instead of unpack(template)[0] [ci skip]

This commit is contained in:
Kazuhiro NISHIYAMA 2021-09-23 09:20:00 +09:00
parent fb976df81f
commit e0c6e8c64a
No known key found for this signature in database
GPG key ID: 262ED8DBB4222F7A
3 changed files with 4 additions and 4 deletions

View file

@ -306,7 +306,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
* ipttl = sock.getsockopt(:IP, :TTL).int * ipttl = sock.getsockopt(:IP, :TTL).int
* *
* optval = sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL) * optval = sock.getsockopt(Socket::IPPROTO_IP, Socket::IP_TTL)
* ipttl = optval.unpack("i")[0] * ipttl = optval.unpack1("i")
* *
* Option values may be structs. Decoding them can be complex as it involves * Option values may be structs. Decoding them can be complex as it involves
* examining your system headers to determine the correct definition. An * examining your system headers to determine the correct definition. An

2
io.c
View file

@ -3324,7 +3324,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex)
* # each record is prefixed by its 32-bit length * # each record is prefixed by its 32-bit length
* open("variable-record-file") do |f| * open("variable-record-file") do |f|
* while len = f.read(4) * while len = f.read(4)
* len = len.unpack("N")[0] # 32-bit length * len = len.unpack1("N") # 32-bit length
* record = f.read(len) # This returns a string even if len is 0. * record = f.read(len) # This returns a string even if len is 0.
* end * end
* end * end

View file

@ -10831,7 +10831,7 @@ enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl, int cr)
* *
* "abc\u3042\x81".scrub #=> "abc\u3042\uFFFD" * "abc\u3042\x81".scrub #=> "abc\u3042\uFFFD"
* "abc\u3042\x81".scrub("*") #=> "abc\u3042*" * "abc\u3042\x81".scrub("*") #=> "abc\u3042*"
* "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>" * "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack1('H*')+'>' } #=> "abc\u3042<e380>"
*/ */
static VALUE static VALUE
str_scrub(int argc, VALUE *argv, VALUE str) str_scrub(int argc, VALUE *argv, VALUE str)
@ -10853,7 +10853,7 @@ str_scrub(int argc, VALUE *argv, VALUE str)
* *
* "abc\u3042\x81".scrub! #=> "abc\u3042\uFFFD" * "abc\u3042\x81".scrub! #=> "abc\u3042\uFFFD"
* "abc\u3042\x81".scrub!("*") #=> "abc\u3042*" * "abc\u3042\x81".scrub!("*") #=> "abc\u3042*"
* "abc\u3042\xE3\x80".scrub!{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>" * "abc\u3042\xE3\x80".scrub!{|bytes| '<'+bytes.unpack1('H*')+'>' } #=> "abc\u3042<e380>"
*/ */
static VALUE static VALUE
str_scrub_bang(int argc, VALUE *argv, VALUE str) str_scrub_bang(int argc, VALUE *argv, VALUE str)