diff --git a/NEWS.md b/NEWS.md index 14f7ed779371c3..26b451be15c06a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -242,13 +242,13 @@ details of the default gems or bundled gems. * Kernel#caller, Thread::Backtrace::Location’s methods, etc. are also changed accordingly. Old: - ``` + ```text test.rb:1:in `foo': undefined method `time' for an instance of Integer from test.rb:2:in `
' ``` New: - ``` + ```text test.rb:1:in 'Object#foo': undefined method 'time' for an instance of Integer from test.rb:2:in '
' ``` @@ -259,21 +259,24 @@ details of the default gems or bundled gems. * Other keys now have spaces around `=>`: `'{"user" => 1}'`, while previously they didn't: `'{"user"=>1}'` * Kernel#Float() now accepts a decimal string with decimal part omitted. [[Feature #20705]] - ``` + + ```rb Float("1.") #=> 1.0 (previously, an ArgumentError was raised) Float("1.E-1") #=> 0.1 (previously, an ArgumentError was raised) ``` * String#to_f now accepts a decimal string with decimal part omitted. [[Feature #20705]] Note that the result changes when an exponent is specified. - ``` + + ```rb "1.".to_f #=> 1.0 "1.E-1".to_f #=> 0.1 (previously, 1.0 was returned) ``` * Object#singleton_method now returns methods in modules prepended to or included in the receiver's singleton class. [[Bug #20620]] - ``` + + ```rb o = Object.new o.extend(Module.new{def a = 1}) o.singleton_method(:a).call #=> 1 @@ -288,17 +291,17 @@ details of the default gems or bundled gems. * Net::HTTP * Removed the following deprecated constants: - `Net::HTTP::ProxyMod` - `Net::NetPrivate::HTTPRequest` - `Net::HTTPInformationCode` - `Net::HTTPSuccessCode` - `Net::HTTPRedirectionCode` - `Net::HTTPRetriableCode` - `Net::HTTPClientErrorCode` - `Net::HTTPFatalErrorCode` - `Net::HTTPServerErrorCode` - `Net::HTTPResponseReceiver` - `Net::HTTPResponceReceiver` + * `Net::HTTP::ProxyMod` + * `Net::NetPrivate::HTTPRequest` + * `Net::HTTPInformationCode` + * `Net::HTTPSuccessCode` + * `Net::HTTPRedirectionCode` + * `Net::HTTPRetriableCode` + * `Net::HTTPClientErrorCode` + * `Net::HTTPFatalErrorCode` + * `Net::HTTPServerErrorCode` + * `Net::HTTPResponseReceiver` + * `Net::HTTPResponceReceiver` These constants were deprecated from 2012. diff --git a/benchmark/README.md b/benchmark/README.md index e11381cad93e2c..6dc4bf8d1e759f 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -26,7 +26,7 @@ benchmark-driver benchmark/*.yml See also: -```console +```text Usage: benchmark-driver [options] RUBY|YAML... -r, --runner TYPE Specify runner type: ips, time, memory, once, block (default: ips) -o, --output TYPE Specify output type: compare, simple, markdown, record, all (default: compare) diff --git a/doc/command_line/environment.md b/doc/command_line/environment.md index 798074309294b6..8f6d595f6c2f25 100644 --- a/doc/command_line/environment.md +++ b/doc/command_line/environment.md @@ -151,14 +151,15 @@ nil Ruby code may also define warnings for certain categories; these are the default settings for the defined categories: -``` +```ruby Warning[:experimental] # => true Warning[:deprecated] # => false Warning[:performance] # => false ``` They may also be set: -``` + +```ruby Warning[:experimental] = false Warning[:deprecated] = true Warning[:performance] = true diff --git a/doc/contributing/building_ruby.md b/doc/contributing/building_ruby.md index 0acad0405c194c..5aad29ebfebfb8 100644 --- a/doc/contributing/building_ruby.md +++ b/doc/contributing/building_ruby.md @@ -32,7 +32,7 @@ the OS default place, typically using Homebrew on macOS, pass the `--with-opt-dir` (or `--with-gmp-dir` for gmp) option to `configure`. - ``` shell + ```sh configure --with-opt-dir=$(brew --prefix gmp):$(brew --prefix jemalloc) ``` @@ -43,7 +43,7 @@ latter environment variable is not embedded and is only used when building the extension libraries. - ``` shell + ```sh export CONFIGURE_ARGS="" for ext in openssl readline libyaml zlib; do CONFIGURE_ARGS="${CONFIGURE_ARGS} --with-$ext-dir=$(brew --prefix $ext)" @@ -71,7 +71,7 @@ Download the latest tarball from [Download Ruby] page and extract it. Example for Ruby 3.0.2: - ``` shell + ```sh tar -xzf ruby-3.0.2.tar.gz cd ruby-3.0.2 ``` @@ -80,20 +80,20 @@ Checkout the CRuby source code: - ``` shell + ```sh git clone https://github.com/ruby/ruby.git cd ruby ``` Generate the configure file: - ``` shell + ```sh ./autogen.sh ``` 2. Create a `build` directory separate from the source directory: - ``` shell + ```sh mkdir build && cd build ``` @@ -102,13 +102,13 @@ 3. We'll install Ruby in `~/.rubies/ruby-master`, so create the directory: - ``` shell + ```sh mkdir ~/.rubies ``` 4. Run configure: - ``` shell + ```sh ../configure --prefix="${HOME}/.rubies/ruby-master" ``` @@ -117,7 +117,7 @@ 5. Build Ruby: - ``` shell + ```sh make ``` @@ -125,7 +125,7 @@ 7. Install Ruby: - ``` shell + ```sh make install ``` @@ -159,7 +159,7 @@ In GNU make[^caution-gmake-3] and BSD make implementations, to run a specific ma parallel, pass the flag `-j`. For instance, to run tests on 8 processes, use: -``` shell +```sh make test-all -j8 ``` @@ -169,7 +169,7 @@ Having the right `--jobs` flag will ensure all processors are utilized when building software projects. To do this effectively, you can set `MAKEFLAGS` in your shell configuration/profile: -``` shell +```sh # On macOS with Fish shell: export MAKEFLAGS="--jobs "(sysctl -n hw.ncpu) @@ -193,7 +193,7 @@ certain features. It can be useful in Ruby development because it allows for faster build times. Miniruby is built before Ruby. A functional Miniruby is required to build Ruby. To build Miniruby: -``` shell +```sh make miniruby ``` @@ -215,7 +215,7 @@ following make targets: You should configure Ruby without optimization and other flags that may interfere with debugging: -``` shell +```sh ./configure --enable-debug-env optflags="-O0 -fno-omit-frame-pointer" ``` @@ -225,7 +225,7 @@ Using the address sanitizer (ASAN) is a great way to detect memory issues. It can detect memory safety issues in Ruby itself, and also in any C extensions compiled with and loaded into a Ruby compiled with ASAN. -``` shell +```sh ./autogen.sh mkdir build && cd build ../configure CC=clang-18 cflags="-fsanitize=address -fno-omit-frame-pointer -DUSE_MN_THREADS=0" # and any other options you might like @@ -239,7 +239,7 @@ two hours on my laptop); the `RUBY_TEST_TIMEOUT_SCALE` and `SYNTAX_SUGEST_TIMEOUT` variables are required to make sure tests don't spuriously fail with timeouts when in fact they're just slow. -``` shell +```sh RUBY_TEST_TIMEOUT_SCALE=5 SYNTAX_SUGGEST_TIMEOUT=600 make check ``` @@ -274,7 +274,7 @@ Please note, however, the following caveats! You need to be able to use gcc (gcov) and lcov visualizer. -``` shell +```sh ./autogen.sh ./configure --enable-gcov make diff --git a/doc/contributing/documentation_guide.md b/doc/contributing/documentation_guide.md index f93fc411652e96..a4df55e2449c5a 100644 --- a/doc/contributing/documentation_guide.md +++ b/doc/contributing/documentation_guide.md @@ -95,7 +95,7 @@ involving new files `doc/*.rdoc`: Example: - ``` + ```c /* * call-seq: * each_byte {|byte| ... } -> self @@ -173,12 +173,13 @@ Code that is a simple string should include the quote marks. Most often, the name of a class, module, or method is auto-linked: -``` +```rdoc - Float. - Enumerable. - File.new - File#read. ``` + renders as: > - Float. @@ -189,7 +190,7 @@ renders as: In general, \RDoc's auto-linking should not be suppressed. For example, we should write just plain _Float_ (which is auto-linked): -``` +```rdoc Returns a Float. ``` @@ -200,13 +201,13 @@ which renders as: However, _do_ suppress auto-linking when the word in question does not refer to a Ruby entity (e.g., some uses of _Class_ or _English_): -``` +```rdoc \Class variables can be tricky. ``` renders as: -> \\Class variables can be tricky. +> Class variables can be tricky. Also, _do_ suppress auto-linking when the word in question refers to the current document @@ -216,7 +217,7 @@ In this case you may consider forcing the name to [monofont](rdoc-ref:RDoc::MarkupReference@Monofont), which suppresses auto-linking, and also emphasizes that the word is a class name: -``` +```rdoc A +Float+ object represents .... ``` @@ -231,7 +232,7 @@ you might write simply the lowercase _array_. Instead of: -``` +```rdoc For an empty Array, .... ``` @@ -241,7 +242,7 @@ which renders as: you might write: -``` +```rdoc For an empty array, .... ``` @@ -398,13 +399,13 @@ the method accepts, so those need to be documented using \RDoc directive For a singleton method, use the form: -``` +```rdoc class_name.method_name(method_args) {|block_args| ... } -> return_type ``` Example: -``` +```rdoc * call-seq: * Hash.new(default_value = nil) -> new_hash * Hash.new {|hash, key| ... } -> new_hash @@ -413,19 +414,20 @@ Example: For an instance method, use the form (omitting any prefix, just as RDoc does for a Ruby-coded method): -``` +```rdoc method_name(method_args) {|block_args| ... } -> return_type ``` + For example, in Array, use: -``` +```rdoc * call-seq: * count -> integer * count(obj) -> integer * count {|element| ... } -> integer ``` -``` +```rdoc * call-seq: * <=> other -> -1, 0, 1, or nil ``` @@ -433,7 +435,7 @@ For example, in Array, use: For a binary-operator style method (e.g., Array#&), cite `self` in the call-seq (not, e.g., `array` or `receiver`): -``` +```rdoc * call-seq: * self & other_array -> new_array ``` @@ -449,7 +451,7 @@ Arguments: or an explicit argument, use a `call-seq` with optional arguments. For example, use: - ``` + ```rdoc * call-seq: * respond_to?(symbol, include_all = false) -> true or false ``` @@ -458,7 +460,7 @@ Arguments: use a `call-seq` with separate lines. For example, in Enumerable, use: - ``` + ```rdoc * call-seq: * max -> element * max(n) -> array @@ -472,7 +474,7 @@ Block: - If the method accepts a block, but returns an Enumerator when the block is omitted, the `call-seq` should show both forms: - ``` + ```rdoc * call-seq: * array.select {|element| ... } -> new_array * array.select -> new_enumerator @@ -505,9 +507,7 @@ an entire paragraph. For `Array#count`, the synopsis is: -``` -Returns a count of specified elements. -``` +> Returns a count of specified elements. This is great as it is short and descriptive. Avoid documenting too much in the synopsis, stick to the most important information @@ -550,7 +550,7 @@ but return a new Enumerator if the block is not given; in that case, do not provide an example, but do state the fact (with the auto-linking uppercase Enumerator): -``` +```rdoc * With no block given, returns a new Enumerator. ``` diff --git a/doc/contributing/making_changes_to_stdlibs.md b/doc/contributing/making_changes_to_stdlibs.md index 3b33092fead20f..721ba842896a25 100644 --- a/doc/contributing/making_changes_to_stdlibs.md +++ b/doc/contributing/making_changes_to_stdlibs.md @@ -14,7 +14,7 @@ You can find the list of maintainers [here](https://docs.ruby-lang.org/en/master First, install its dependencies using: -``` +```shell bundle install ``` @@ -22,7 +22,7 @@ bundle install If the library has a `/ext` directory, it has C files that you need to compile with: -``` +```shell bundle exec rake compile ``` @@ -32,18 +32,18 @@ All standard libraries use [test-unit](https://github.com/test-unit/test-unit) a To run all tests: -``` +```shell bundle exec rake test ``` To run a single test file: -``` +```shell bundle exec rake test TEST="test/test_foo.rb" ``` To run a single test case: -``` +```shell bundle exec rake test TEST="test/test_foo.rb" TESTOPS="--name=/test_mytest/" ``` diff --git a/doc/contributing/testing_ruby.md b/doc/contributing/testing_ruby.md index dfb7fb3a658161..ca6a991917bf13 100644 --- a/doc/contributing/testing_ruby.md +++ b/doc/contributing/testing_ruby.md @@ -10,38 +10,38 @@ We can run any of the make scripts [in parallel](building_ruby.md#label-Running+ This is a small test suite that runs on Miniruby (see [building Ruby](building_ruby.md#label-Miniruby+vs+Ruby)). We can run it with: - ``` + ```sh make btest ``` To run it with logs, we can use: - ``` + ```sh make btest OPTS=-v ``` To run individual bootstrap tests, we can either specify a list of filenames or use the `--sets` flag in the variable `BTESTS`: - ``` - make btest BTESTS="bootstraptest/test_fork.rb bootstraptest/tes_gc.rb" + ```sh + make btest BTESTS="../bootstraptest/test_fork.rb ../bootstraptest/test_gc.rb" make btest BTESTS="--sets=fork,gc" ``` If we want to run the bootstrap test suite on Ruby (not Miniruby), we can use: - ``` + ```sh make test ``` To run it with logs, we can use: - ``` + ```sh make test OPTS=-v ``` To run a file or directory with GNU make, we can use: - ``` + ```sh make test/ruby/test_foo.rb make test/ruby/test_foo.rb TESTOPTS="-n /test_bar/" ``` @@ -50,44 +50,44 @@ We can run any of the make scripts [in parallel](building_ruby.md#label-Running+ This is a more comprehensive test suite that runs on Ruby. We can run it with: - ``` + ```sh make test-all ``` We can run a specific test directory in this suite using the `TESTS` option, for example: - ``` + ```sh make test-all TESTS=test/rubygems ``` We can run a specific test file in this suite by also using the `TESTS` option, for example: - ``` + ```sh make test-all TESTS=test/ruby/test_array.rb ``` We can run a specific test in this suite using the `TESTS` option, specifying first the file name, and then the test name, prefixed with `--name`. For example: - ``` + ```sh make test-all TESTS="../test/ruby/test_alias.rb --name=TestAlias#test_alias_with_zsuper_method" ``` To run these specs with logs, we can use: - ``` + ```sh make test-all TESTS=-v ``` We can display the help of the `TESTS` option: - ``` + ```sh make test-all TESTS=--help ``` If we would like to run the `test/`, `bootstraptest/` and `spec/` test suites (the `spec/` is explained in a later section), we can run - ``` + ```sh make check ``` @@ -95,37 +95,37 @@ We can run any of the make scripts [in parallel](building_ruby.md#label-Running+ This is a test suite that exists in [the Ruby spec repository](https://github.com/ruby/spec) and is mirrored into the `spec/ruby` directory in the Ruby repository. It tests the behavior of the Ruby programming language. We can run this using: - ``` + ```sh make test-spec ``` To run a specific directory, we can use `SPECOPTS` to specify the directory: - ``` + ```sh make test-spec SPECOPTS=spec/ruby/core/array ``` To run a specific file, we can also use `SPECOPTS` to specify the file: - ``` + ```sh make test-spec SPECOPTS=spec/ruby/core/array/any_spec.rb ``` To run a specific test, we can use the `--example` flag to match against the test name: - ``` + ```sh make test-spec SPECOPTS="../spec/ruby/core/array/any_spec.rb --example='is false if the array is empty'" ``` To run these specs with logs, we can use: - ``` + ```sh make test-spec SPECOPTS=-Vfs ``` To run a ruby-spec file or directory with GNU make, we can use - ``` + ```sh make spec/ruby/core/foo/bar_spec.rb ``` @@ -133,13 +133,13 @@ We can run any of the make scripts [in parallel](building_ruby.md#label-Running+ The bundler test suite exists in [the RubyGems repository](https://github.com/rubygems/rubygems/tree/master/bundler/spec) and is mirrored into the `spec/bundler` directory in the Ruby repository. We can run this using: - ``` + ```sh make test-bundler ``` To run a specific bundler spec file, we can use `BUNDLER_SPECS` as follows: - ``` + ```sh make test-bundler BUNDLER_SPECS=commands/exec_spec.rb ``` @@ -149,7 +149,7 @@ We can run any of the make scripts [in parallel](building_ruby.md#label-Running+ If we see failing tests related to the zlib library on s390x CPU architecture, we can run the test suites with `DFLTCC=0` to pass: -``` +```sh DFLTCC=0 make check ``` diff --git a/doc/exceptions.md b/doc/exceptions.md index ae03438519b1fa..65aa2bca6cfa56 100644 --- a/doc/exceptions.md +++ b/doc/exceptions.md @@ -9,7 +9,7 @@ and may need to be handled. Code throughout the Ruby core, Ruby standard library, and Ruby gems generates exceptions in certain circumstances: -``` +```rb File.open('nope.txt') # Raises Errno::ENOENT: "No such file or directory" ``` @@ -38,7 +38,7 @@ and may prevent the program from exiting. A simple example: -``` +```rb begin raise 'Boom!' # Raises an exception, transfers control. puts 'Will not get here.' @@ -50,7 +50,7 @@ puts 'Got here.' Output: -``` +```text Rescued an exception. Got here. ``` @@ -94,7 +94,7 @@ The rescue clause rescues both the specified class (or StandardError if none given) or any of its subclasses; see [Built-In Exception Class Hierarchy](rdoc-ref:Exception@Built-In+Exception+Class+Hierarchy). -``` +```rb begin 1 / 0 # Raises ZeroDivisionError, a subclass of StandardError. rescue @@ -104,7 +104,7 @@ end Output: -``` +```text Rescued ZeroDivisionError ``` @@ -113,7 +113,7 @@ only that class (or one of its subclasses) is rescued; this example exits with a ZeroDivisionError, which was not rescued because it is not ArgumentError or one of its subclasses: -``` +```rb begin 1 / 0 rescue ArgumentError @@ -125,7 +125,7 @@ A `rescue` statement may specify multiple classes, which means that its code rescues an exception of any of the given classes (or their subclasses): -``` +```rb begin 1 / 0 rescue FloatDomainError, ZeroDivisionError @@ -139,7 +139,7 @@ An exception handler may contain multiple rescue clauses; in that case, the first clause that rescues the exception does so, and those before and after are ignored: -``` +```rb begin Dir.open('nosuch') rescue Errno::ENOTDIR @@ -151,7 +151,7 @@ end Output: -``` +```text Rescued Errno::ENOENT ``` @@ -161,7 +161,7 @@ A `rescue` statement may specify a variable whose value becomes the rescued exception (an instance of Exception or one of its subclasses: -``` +```rb begin 1 / 0 rescue => x @@ -172,7 +172,7 @@ end Output: -``` +```text ZeroDivisionError divided by 0 ``` @@ -188,7 +188,7 @@ there: Example: -``` +```rb begin 1 / 0 rescue @@ -199,7 +199,7 @@ end Output: -``` +```text # ["t.rb:2:in `/'", "t.rb:2:in `
'"] ``` @@ -212,7 +212,7 @@ elsewhere, the method returns `nil`. Example: -``` +```rb begin raise('Boom 0') rescue => x0 @@ -232,7 +232,7 @@ end Output: -``` +```text Exception: #; $!: #; cause: nil. Exception: #; $!: #; cause: #. Exception: #; $!: #; cause: #. @@ -246,7 +246,7 @@ The `else` clause: - Contains code that is to be executed if no exception is raised in the begin clause. - Ends with the first following `ensure` or `end` statement. -``` +```rb begin puts 'Begin.' rescue @@ -258,7 +258,7 @@ end Output: -``` +```text Begin. No exception raised. ``` @@ -273,7 +273,7 @@ The ensure clause: and regardless of whether a raised exception is handled. - Ends with the first following `end` statement. -``` +```rb def foo(boom: false) puts 'Begin.' raise 'Boom!' if boom @@ -291,7 +291,7 @@ foo(boom: false) Output: -``` +```text Begin. Rescued an exception! Always do this. @@ -314,7 +314,7 @@ An exception handler may also be implemented as: - A method body: - ``` + ```rb def foo(boom: false) # Serves as beginning of exception handler. puts 'Begin.' raise 'Boom!' if boom @@ -327,7 +327,7 @@ An exception handler may also be implemented as: - A block: - ``` + ```rb Dir.chdir('.') do |dir| # Serves as beginning of exception handler. raise 'Boom!' rescue @@ -349,7 +349,7 @@ a rescuing clause: - Calls method `raise` with no argument, which raises the rescued exception: -``` +```rb begin 1 / 0 rescue ZeroDivisionError @@ -360,7 +360,7 @@ end Output: -``` +```text ruby t.rb t.rb:2:in `/': divided by 0 (ZeroDivisionError) from t.rb:2:in `
' @@ -374,7 +374,7 @@ for example, if it must access a possibly-volatile resource it can be useful to try the access more than once (in the hope that it may become available): -``` +```rb retries = 0 begin puts "Try ##{retries}." @@ -391,7 +391,7 @@ rescue end ``` -``` +```text Try #0. Rescued retry #0. Retrying @@ -419,7 +419,7 @@ Each should be a subclass of one of the built-in exception classes (commonly StandardError or RuntimeError); see [Built-In Exception Class Hierarchy](rdoc-ref:Exception@Built-In+Exception+Class+Hierarchy). -``` +```rb class MyException < StandardError; end ``` diff --git a/doc/fiber.md b/doc/fiber.md index a334faf7396187..2bc1ff96b2501a 100644 --- a/doc/fiber.md +++ b/doc/fiber.md @@ -6,7 +6,7 @@ Fibers provide a mechanism for cooperative concurrency. Fibers execute a user-provided block. During the execution, the block may call `Fiber.yield` or `Fiber.transfer` to switch to another fiber. `Fiber#resume` is used to continue execution from the point where `Fiber.yield` was called. -``` ruby +```rb #!/usr/bin/env ruby puts "1: Start program." @@ -38,13 +38,13 @@ instrumentation. To set the scheduler for the current thread: -``` ruby +```rb Fiber.set_scheduler(MyScheduler.new) ``` When the thread exits, there is an implicit call to `set_scheduler`: -``` ruby +```rb Fiber.set_scheduler(nil) ``` @@ -60,7 +60,7 @@ no changes. This is the interface you need to implement. -``` ruby +```rb class Scheduler # Wait for the specified process ID to exit. # This hook is optional. @@ -166,7 +166,7 @@ program. Fibers can be used to create non-blocking execution contexts. -``` ruby +```rb Fiber.new do puts Fiber.current.blocking? # false @@ -184,7 +184,7 @@ end.resume We also introduce a new method which simplifies the creation of these non-blocking fibers: -``` ruby +```rb Fiber.schedule do puts Fiber.current.blocking? # false end @@ -196,7 +196,7 @@ fibers. You can also create blocking execution contexts: -``` ruby +```rb Fiber.new(blocking: true) do # Won't use the scheduler: sleep(n) diff --git a/doc/ractor.md b/doc/ractor.md index 7a69e839de7a27..6ed0eadfcd26d9 100644 --- a/doc/ractor.md +++ b/doc/ractor.md @@ -212,7 +212,7 @@ For message sending and receiving, there are two types of APIs: push type and pu Each Ractor has _incoming-port_ and _outgoing-port_. Incoming-port is connected to the infinite sized incoming queue. -``` +```text Ractor r +-------------------------------------------+ | incoming outgoing | @@ -258,8 +258,7 @@ r.take # Receive from r's outgoing port The last example shows the following ractor network. -``` - +```text +------+ +---+ * main |------> * r *---+ +------+ +---+ | @@ -875,17 +874,17 @@ p Ractor.select(*rs, Ractor.current) #=> [:receive, "r0r10r9r8r7r6r5r4r3r2r1"] r.send "e0" p Ractor.select(*rs, Ractor.current) #=> -# terminated with exception (report_on_exception is true): -Traceback (most recent call last): - 2: from /home/ko1/src/ruby/trunk/test.rb:7:in `block (2 levels) in
' - 1: from /home/ko1/src/ruby/trunk/test.rb:7:in `loop' -/home/ko1/src/ruby/trunk/test.rb:9:in `block (3 levels) in
': unhandled exception -Traceback (most recent call last): - 2: from /home/ko1/src/ruby/trunk/test.rb:7:in `block (2 levels) in
' - 1: from /home/ko1/src/ruby/trunk/test.rb:7:in `loop' -/home/ko1/src/ruby/trunk/test.rb:9:in `block (3 levels) in
': unhandled exception - 1: from /home/ko1/src/ruby/trunk/test.rb:21:in `
' -:69:in `select': thrown by remote Ractor. (Ractor::RemoteError) +# terminated with exception (report_on_exception is true): +# Traceback (most recent call last): +# 2: from /home/ko1/src/ruby/trunk/test.rb:7:in `block (2 levels) in
' +# 1: from /home/ko1/src/ruby/trunk/test.rb:7:in `loop' +# /home/ko1/src/ruby/trunk/test.rb:9:in `block (3 levels) in
': unhandled exception +# Traceback (most recent call last): +# 2: from /home/ko1/src/ruby/trunk/test.rb:7:in `block (2 levels) in
' +# 1: from /home/ko1/src/ruby/trunk/test.rb:7:in `loop' +# /home/ko1/src/ruby/trunk/test.rb:9:in `block (3 levels) in
': unhandled exception +# 1: from /home/ko1/src/ruby/trunk/test.rb:21:in `
' +# :69:in `select': thrown by remote Ractor. (Ractor::RemoteError) ``` ```ruby diff --git a/doc/ruby/option_dump.md b/doc/ruby/option_dump.md index 331c248e507ace..cb5fb02dab961c 100644 --- a/doc/ruby/option_dump.md +++ b/doc/ruby/option_dump.md @@ -89,7 +89,7 @@ The supported dump items: - `yydebug`: Debugging information from yacc parser generator: - ```sh + ```text $ ruby --dump=yydebug t.rb Starting parse Entering state 0 diff --git a/doc/ruby/options.md b/doc/ruby/options.md index c4d7c92a1ceb9c..6e0278e143f328 100644 --- a/doc/ruby/options.md +++ b/doc/ruby/options.md @@ -320,9 +320,9 @@ See also: ### `-n`: Run Program in `gets` Loop -Option `-n` runs your program in a Kernel#gets loop: +Option `-n` runs your program in a `Kernel#gets` loop: -``` +```ruby while gets # Your Ruby code. end @@ -493,14 +493,15 @@ nil Ruby code may also define warnings for certain categories; these are the default settings for the defined categories: -``` +```rb Warning[:experimental] # => true Warning[:deprecated] # => false Warning[:performance] # => false ``` They may also be set: -``` + +```rb Warning[:experimental] = false Warning[:deprecated] = true Warning[:performance] = true diff --git a/doc/strscan/helper_methods.md b/doc/strscan/helper_methods.md index 6555a2ce66159f..9fb1d79bba91f7 100644 --- a/doc/strscan/helper_methods.md +++ b/doc/strscan/helper_methods.md @@ -10,7 +10,7 @@ Display scanner's situation: - Character position (`#charpos`) - Target string (`#rest`) and size (`#rest_size`). -``` +```rb scanner = StringScanner.new('foobarbaz') scanner.scan(/foo/) put_situation(scanner) @@ -25,7 +25,7 @@ put_situation(scanner) Display the scanner's match values: -``` +```rb scanner = StringScanner.new('Fri Dec 12 1975 14:39') pattern = /(?\w+) (?\w+) (?\d+) / scanner.match?(pattern) @@ -53,7 +53,7 @@ put_match_values(scanner) Returns whether the scanner's match values are all properly cleared: -``` +```rb scanner = StringScanner.new('foobarbaz') match_values_cleared?(scanner) # => true put_match_values(scanner) @@ -75,7 +75,7 @@ match_values_cleared?(scanner) # => false ## The Code -``` +```rb def put_situation(scanner) puts '# Situation:' puts "# pos: #{scanner.pos}" @@ -83,9 +83,7 @@ def put_situation(scanner) puts "# rest: #{scanner.rest.inspect}" puts "# rest_size: #{scanner.rest_size}" end -``` -``` def put_match_values(scanner) puts '# Basic match values:' puts "# matched?: #{scanner.matched?}" @@ -109,9 +107,7 @@ def put_match_values(scanner) end end end -``` -``` def match_values_cleared?(scanner) scanner.matched? == false && scanner.matched_size.nil? && diff --git a/doc/strscan/methods/get_byte.md b/doc/strscan/methods/get_byte.md index 2f23be189947bd..3208d77158b342 100644 --- a/doc/strscan/methods/get_byte.md +++ b/doc/strscan/methods/get_byte.md @@ -10,7 +10,7 @@ Returns the next byte, if available: - Increments the [byte position][2]. - Adjusts the [character position][7]. - ``` + ```rb scanner = StringScanner.new(HIRAGANA_TEXT) # => # scanner.string # => "こんにちは" @@ -24,7 +24,7 @@ Returns the next byte, if available: - Otherwise, returns `nil`, and does not change the positions. - ``` + ```rb scanner.terminate [scanner.get_byte, scanner.pos, scanner.charpos] # => [nil, 15, 5] ``` diff --git a/doc/strscan/methods/get_charpos.md b/doc/strscan/methods/get_charpos.md index f77563c860029f..954fcf5b44e599 100644 --- a/doc/strscan/methods/get_charpos.md +++ b/doc/strscan/methods/get_charpos.md @@ -5,7 +5,7 @@ Returns the [character position][7] (initially zero), which may be different from the [byte position][2] given by method #pos: -``` +```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" scanner.getch # => "こ" # 3-byte character. diff --git a/doc/strscan/methods/get_pos.md b/doc/strscan/methods/get_pos.md index 56bcef32745a01..81bbb2345e9268 100644 --- a/doc/strscan/methods/get_pos.md +++ b/doc/strscan/methods/get_pos.md @@ -4,7 +4,7 @@ call-seq: Returns the integer [byte position][2], which may be different from the [character position][7]: -``` +```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" scanner.pos # => 0 diff --git a/doc/strscan/methods/getch.md b/doc/strscan/methods/getch.md index b57732ad7c189f..3dd70e4c5be04a 100644 --- a/doc/strscan/methods/getch.md +++ b/doc/strscan/methods/getch.md @@ -12,7 +12,7 @@ if available: - Increments the [byte position][2] by the size (in bytes) of the character. - ``` + ```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" [scanner.getch, scanner.pos, scanner.charpos] # => ["こ", 3, 1] @@ -27,7 +27,7 @@ if available: (that is, not at its beginning), behaves like #get_byte (returns a 1-byte character): - ``` + ```rb scanner.pos = 1 [scanner.getch, scanner.pos, scanner.charpos] # => ["\x81", 2, 2] [scanner.getch, scanner.pos, scanner.charpos] # => ["\x93", 3, 1] @@ -37,7 +37,7 @@ if available: - If the [position][2] is at the end of the [stored string][1], returns `nil` and does not modify the positions: - ``` + ```rb scanner.terminate [scanner.getch, scanner.pos, scanner.charpos] # => [nil, 15, 5] ``` diff --git a/doc/strscan/methods/scan.md b/doc/strscan/methods/scan.md index 714fa9910afa5f..7cff36bb97e0b4 100644 --- a/doc/strscan/methods/scan.md +++ b/doc/strscan/methods/scan.md @@ -45,7 +45,7 @@ If the match fails: - Does not increment byte and character positions. - Clears match values. -``` +```rb scanner.scan(/nope/) # => nil match_values_cleared?(scanner) # => true ``` diff --git a/doc/strscan/methods/scan_until.md b/doc/strscan/methods/scan_until.md index 3b7ff2c3a9b593..b98b2bd31b1197 100644 --- a/doc/strscan/methods/scan_until.md +++ b/doc/strscan/methods/scan_until.md @@ -46,7 +46,7 @@ If the match attempt fails: - Returns `nil`. - Does not update positions. -``` +```rb scanner.scan_until(/nope/) # => nil match_values_cleared?(scanner) # => true ``` diff --git a/doc/strscan/methods/set_pos.md b/doc/strscan/methods/set_pos.md index 230177109cbc20..3b7abe65e3379a 100644 --- a/doc/strscan/methods/set_pos.md +++ b/doc/strscan/methods/set_pos.md @@ -9,7 +9,7 @@ Does not affect [match values][9]. For non-negative `n`, sets the position to `n`: -``` +```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" scanner.pos = 3 # => 3 @@ -19,7 +19,7 @@ scanner.charpos # => 1 For negative `n`, counts from the end of the [stored string][1]: -``` +```rb scanner.pos = -9 # => -9 scanner.pos # => 6 scanner.rest # => "にちは" diff --git a/doc/strscan/methods/skip_until.md b/doc/strscan/methods/skip_until.md index 5187a4826fb2c7..b7dacf6da1ee13 100644 --- a/doc/strscan/methods/skip_until.md +++ b/doc/strscan/methods/skip_until.md @@ -10,7 +10,7 @@ If the match attempt succeeds: - Sets [match values][9]. - Returns the size of the matched substring. -``` +```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" scanner.pos = 6 @@ -43,7 +43,7 @@ If the match attempt fails: - Clears match values. - Returns `nil`. -``` +```rb scanner.skip_until(/nope/) # => nil match_values_cleared?(scanner) # => true ``` diff --git a/doc/strscan/methods/terminate.md b/doc/strscan/methods/terminate.md index fd557270996c5b..b03b37d2a289ab 100644 --- a/doc/strscan/methods/terminate.md +++ b/doc/strscan/methods/terminate.md @@ -7,7 +7,7 @@ returns +self+: - Sets both [positions][11] to end-of-stream. - Clears [match values][9]. -``` +```rb scanner = StringScanner.new(HIRAGANA_TEXT) scanner.string # => "こんにちは" scanner.scan_until(/に/) diff --git a/doc/strscan/strscan.md b/doc/strscan/strscan.md index 558568dc437995..dea87e0d43de8c 100644 --- a/doc/strscan/strscan.md +++ b/doc/strscan/strscan.md @@ -1,7 +1,7 @@ \Class `StringScanner` supports processing a stored string as a stream; this code creates a new `StringScanner` object with string `'foobarbaz'`: -``` +```rb require 'strscan' scanner = StringScanner.new('foobarbaz') ``` @@ -10,13 +10,13 @@ scanner = StringScanner.new('foobarbaz') All examples here assume that `StringScanner` has been required: -``` +```rb require 'strscan' ``` Some examples here assume that these constants are defined: -``` +```rb MULTILINE_TEXT = <<~EOT Go placidly amid the noise and haste, and remember what peace there may be in silence. @@ -45,7 +45,7 @@ This code creates a `StringScanner` object (we'll call it simply a _scanner_), and shows some of its basic properties: -``` +```rb scanner = StringScanner.new('foobarbaz') scanner.string # => "foobarbaz" put_situation(scanner) @@ -138,7 +138,7 @@ To get or set the byte position: Many methods use the byte position as the basis for finding matches; many others set, increment, or decrement the byte position: -``` +```rb scanner = StringScanner.new('foobar') scanner.pos # => 0 scanner.scan(/foo/) # => "foo" # Match found. @@ -176,7 +176,7 @@ see: Example (string includes multi-byte characters): -``` +```rb scanner = StringScanner.new(ENGLISH_TEXT) # Five 1-byte characters. scanner.concat(HIRAGANA_TEXT) # Five 3-byte characters scanner.string # => "Helloこんにちは" # Twenty bytes in all. @@ -216,7 +216,7 @@ and its size is returned by method #rest_size. Examples: -``` +```rb scanner = StringScanner.new('foobarbaz') put_situation(scanner) # Situation: @@ -430,7 +430,7 @@ See examples below. Successful basic match attempt (no captures): -``` +```rb scanner = StringScanner.new('foobarbaz') scanner.exist?(/bar/) put_match_values(scanner) @@ -452,7 +452,7 @@ put_match_values(scanner) Failed basic match attempt (no captures); -``` +```rb scanner = StringScanner.new('foobarbaz') scanner.exist?(/nope/) match_values_cleared?(scanner) # => true @@ -460,7 +460,7 @@ match_values_cleared?(scanner) # => true Successful unnamed capture match attempt: -``` +```rb scanner = StringScanner.new('foobarbazbatbam') scanner.exist?(/(foo)bar(baz)bat(bam)/) put_match_values(scanner) @@ -486,7 +486,7 @@ put_match_values(scanner) Successful named capture match attempt; same as unnamed above, except for #named_captures: -``` +```rb scanner = StringScanner.new('foobarbazbatbam') scanner.exist?(/(?foo)bar(?baz)bat(?bam)/) scanner.named_captures # => {"x"=>"foo", "y"=>"baz", "z"=>"bam"} @@ -494,7 +494,7 @@ scanner.named_captures # => {"x"=>"foo", "y"=>"baz", "z"=>"bam"} Failed unnamed capture match attempt: -``` +```rb scanner = StringScanner.new('somestring') scanner.exist?(/(foo)bar(baz)bat(bam)/) match_values_cleared?(scanner) # => true @@ -503,7 +503,7 @@ match_values_cleared?(scanner) # => true Failed named capture match attempt; same as unnamed above, except for #named_captures: -``` +```rb scanner = StringScanner.new('somestring') scanner.exist?(/(?foo)bar(?baz)bat(?bam)/) match_values_cleared?(scanner) # => false @@ -518,7 +518,7 @@ which determines the meaning of `'\A'`: * `false` (the default): matches the current byte position. - ``` + ```rb scanner = StringScanner.new('foobar') scanner.scan(/\A./) # => "f" scanner.scan(/\A./) # => "o" @@ -529,7 +529,7 @@ which determines the meaning of `'\A'`: * `true`: matches the beginning of the target substring; never matches unless the byte position is zero: - ``` + ```rb scanner = StringScanner.new('foobar', fixed_anchor: true) scanner.scan(/\A./) # => "f" scanner.scan(/\A./) # => nil diff --git a/doc/windows.md b/doc/windows.md index b802edf1701f1a..b1f9f5a670d4e0 100644 --- a/doc/windows.md +++ b/doc/windows.md @@ -16,7 +16,7 @@ editor. Ruby core development can be done either in Windows `cmd` like: -``` +```batch ridk enable ucrt64 pacman -S --needed %MINGW_PACKAGE_PREFIX%-openssl %MINGW_PACKAGE_PREFIX%-libyaml %MINGW_PACKAGE_PREFIX%-libffi @@ -34,7 +34,7 @@ make or in MSYS2 `bash` like: -``` +```bash ridk enable ucrt64 bash @@ -85,14 +85,14 @@ make You can use [scoop](https://scoop.sh/) to install them like: - ``` + ```batch scoop install git sed ruby ``` 5. You need to install required libraries using [vcpkg](https://vcpkg.io/) on directory of ruby repository like: - ``` + ```batch vcpkg --triplet x64-windows install ``` @@ -140,13 +140,13 @@ make * Build on the ruby source directory. - ``` + ```text ruby source directory: C:\ruby build directory: C:\ruby install directory: C:\usr\local ``` - ``` + ```batch C: cd \ruby win32\configure --prefix=/usr/local @@ -157,13 +157,13 @@ make * Build on the relative directory from the ruby source directory. - ``` + ```text ruby source directory: C:\ruby build directory: C:\ruby\mswin32 install directory: C:\usr\local ``` - ``` + ```batch C: cd \ruby mkdir mswin32 @@ -176,13 +176,13 @@ make * Build on the different drive. - ``` + ```text ruby source directory: C:\src\ruby build directory: D:\build\ruby install directory: C:\usr\local ``` - ``` + ```batch D: cd D:\build\ruby C:\src\ruby\win32\configure --prefix=/usr/local @@ -193,13 +193,13 @@ make * Build x64 version (requires native x64 VC++ compiler) - ``` + ```text ruby source directory: C:\ruby build directory: C:\ruby install directory: C:\usr\local ``` - ``` + ```batch C: cd \ruby win32\configure --prefix=/usr/local --target=x64-mswin64 @@ -224,7 +224,7 @@ Ruby uses [vcpkg](https://vcpkg.io/) to manage dependencies on mswin platform. You can update and install it under the build directory like: -``` +```batch nmake update-vcpkg # Update baseline version of vcpkg nmake install-vcpkg # Install vcpkg from build directory ``` diff --git a/doc/yjit/yjit.md b/doc/yjit/yjit.md index 284c21f323599f..0024c780b909d3 100644 --- a/doc/yjit/yjit.md +++ b/doc/yjit/yjit.md @@ -36,7 +36,7 @@ If you wish to learn more about the approach taken, here are some conference tal To cite YJIT in your publications, please cite the MPLR 2023 paper: -``` +```BibTeX @inproceedings{yjit_mplr_2023, author = {Chevalier-Boisvert, Maxime and Kokubun, Takashi and Gibbs, Noah and Wu, Si Xing (Alan) and Patterson, Aaron and Issroff, Jemma}, title = {Evaluating YJIT’s Performance in a Production Context: A Pragmatic Approach}, diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md index 5c3256948b87b2..366b484bada1c1 100644 --- a/spec/ruby/CONTRIBUTING.md +++ b/spec/ruby/CONTRIBUTING.md @@ -113,9 +113,9 @@ Also `have_constant`, `have_private_instance_method`, `have_singleton_method`, e } ``` -##### should_not raise_error +##### `should_not raise_error` -**To avoid!** Instead, use an expectation testing what the code in the lambda does. +**Avoid this!** Instead, use an expectation testing what the code in the lambda does. If an exception is raised, it will fail the example anyway. ```ruby diff --git a/tool/lrama/NEWS.md b/tool/lrama/NEWS.md index e12c789d34b18f..a4a92f7a664464 100644 --- a/tool/lrama/NEWS.md +++ b/tool/lrama/NEWS.md @@ -6,7 +6,7 @@ Allow to use aliased named references for actions of RHS in parameterizing rules. -``` +```yacc %rule sum(X, Y): X[summand] '+' Y[addend] { $$ = $summand + $addend } ; ``` @@ -18,7 +18,7 @@ https://github.com/ruby/lrama/pull/410 Allow to use named references for actions of RHS in parameterizing rules caller side. -``` +```yacc opt_nl: '\n'?[nl] { $$ = $nl; } ; ``` @@ -29,7 +29,7 @@ https://github.com/ruby/lrama/pull/414 Allow to define parameterizing rules in the middle of the grammar. -``` +```yacc %rule defined_option(X): /* empty */ | X ; @@ -117,7 +117,7 @@ https://github.com/ruby/lrama/pull/457 Allow to specify tag on callee side of parameterizing rules. -``` +```yacc %union { int i; } @@ -130,7 +130,7 @@ Allow to specify tag on callee side of parameterizing rules. Allow to use named references for actions of RHS in parameterizing rules. -``` +```yacc %rule option(number): /* empty */ | number { $$ = $number; } ; @@ -142,7 +142,7 @@ Allow to use named references for actions of RHS in parameterizing rules. Allow to nested parameterizing rules with tag. -``` +```yacc %union { int i; } @@ -199,7 +199,7 @@ expr -> '(', expr, ')' { $$ = $2; } Support inlining for rules. The `%inline` directive causes all references to symbols to be replaced with its definition. -``` +```yacc %rule %inline op: PLUS { + } | TIMES { * } ; @@ -213,7 +213,7 @@ expr : number { $$ = $1; } as same as -``` +```yacc expr : number { $$ = $1; } | expr '+' expr { $$ = $1 + $3; } | expr '*' expr { $$ = $1 * $3; } @@ -226,7 +226,7 @@ expr : number { $$ = $1; } User can specify the type of mid rule action by tag (``) instead of specifying it with in an action. -``` +```yacc primary: k_case expr_value terms? { $$ = p->case_labels; @@ -241,7 +241,7 @@ primary: k_case expr_value terms? can be written as -``` +```yacc primary: k_case expr_value terms? { $$ = p->case_labels; @@ -302,7 +302,7 @@ In general, these resources are freed by actions or after parsing. However if syntax error happens in parsing, these codes may not be executed. Codes associated to `%destructor` are executed when semantic value is popped from the stack by an error. -``` +```yacc %token NUM %type expr2 %type expr @@ -350,7 +350,7 @@ Lrama provides these five callbacks. Registered functions are called when each e User also needs to access semantic value of their stack in grammar action. `$:n` provides the way to access to it. `$:n` is translated to the minus index from the top of the stack. For example -``` +```yacc primary: k_if expr_value then compstmt if_tail k_end { /*% ripper: if!($:2, $:4, $:5) %*/ @@ -375,7 +375,7 @@ https://github.com/ruby/lrama/pull/344 Allow to pass an instantiated rule to other parameterizing rules. -``` +```yacc %rule constant(X) : X ; @@ -392,7 +392,7 @@ program : option(constant(number)) // Nested rule Allow to use nested parameterizing rules when define parameterizing rules. -``` +```yacc %rule option(x) : /* empty */ | X ; @@ -419,7 +419,7 @@ https://github.com/ruby/lrama/pull/337 Allow to define parameterizing rule by `%rule` directive. -``` +```yacc %rule pair(X, Y): X Y { $$ = $1 + $2; } ; @@ -442,7 +442,7 @@ https://github.com/ruby/lrama/pull/285 Allow to specify type of rules by specifying tag, `` in below example. Tag is post-modification style. -``` +```yacc %union { int i; } @@ -500,7 +500,7 @@ https://github.com/ruby/lrama/pull/204 Parameterizing rules are template of rules. It's very common pattern to write "list" grammar rule like: -``` +```yacc opt_args: /* none */ | args ; @@ -555,7 +555,7 @@ https://github.com/ruby/lrama/pull/44 Instead of positional references like `$1` or `$$`, named references allow to access to symbol by name. -``` +```yacc primary: k_class cpath superclass bodystmt k_end { $primary = new_class($cpath, $bodystmt, $superclass); @@ -564,7 +564,7 @@ primary: k_class cpath superclass bodystmt k_end Alias name can be declared. -``` +```yacc expr[result]: expr[ex-left] '+' expr[ex.right] { $result = $[ex-left] + $[ex.right];