summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMau Magnaguagno <maumagnaguagno@gmail.com>2022-02-28 22:05:49 -0300
committerGitHub <noreply@github.com>2022-03-01 10:05:49 +0900
commit347c3faf8eba55cdb09861c29f8646d78053fa5c (patch)
tree4dd55fbb60c06f760ae2a97c3f3f4e367fd77ce2
parent1a20bb1c986961786a981af95ed964f0625eeed0 (diff)
[DOC] Fix String#getbyte doc
* String#getbyte returns `nil` if `index` is out of range. * Add String#getbyte example with nil output. * Modify String#getbyte example to use negative index.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5586 Merged-By: nobu <nobu@ruby-lang.org>
-rw-r--r--string.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/string.c b/string.c
index 4b35b076e0..55cdace9f8 100644
--- a/string.c
+++ b/string.c
@@ -6070,13 +6070,14 @@ rb_str_chr(VALUE str)
/*
* call-seq:
- * getbyte(index) -> integer
+ * getbyte(index) -> integer or nil
*
- * Returns the byte at zero-based +index+ as an integer:
+ * Returns the byte at zero-based +index+ as an integer, or +nil+ if +index+ is out of range:
*
- * s = 'abcde' # => "abcde"
- * s.getbyte(0) # => 97
- * s.getbyte(1) # => 98
+ * s = 'abcde' # => "abcde"
+ * s.getbyte(0) # => 97
+ * s.getbyte(-1) # => 101
+ * s.getbyte(5) # => nil
*
* Related: String#setbyte.
*/