Interactive Ruby

Interactive Ruby (IRB、irb) は、Rubyを対話的に実行 (REPL) するためのシェルである。

Interactive Ruby
Interactive Ruby
開発元 石塚圭樹
最新版
1.15.1 / 2025年1月22日 (18か月前) (2025-01-22)[1]
リポジトリ ウィキデータを編集
プログラミング
言語
Ruby
対応OS クロスプラットフォーム
種別 シェル
ライセンス 2条項BSDライセンス
公式サイト github.com/ruby/irb ウィキデータを編集
テンプレートを表示

Interactive Ruby (IRB、irb) は、Rubyを対話的に実行 (REPL) するためのシェルである。

irbコマンドを実行することでコマンドプロンプトが表示され、Rubyの式を入力することでそれが実行され、結果が表示される。 Readlineがインストールされている場合、コマンドライン編集や履歴などの機能を利用できる。

Ruby 2.7に添付されているirbでは、Readlineに代わってRelineが採用された[2]

irbは石塚圭樹によって開発された。

構文と実行例

構文:

irb [options] file_name opts

実行例:

irb(main):001:0> n = 5
=> 5
irb(main):002:0> def fact(n)
irb(main):003:1>   if n <= 1
irb(main):004:2>     1
irb(main):005:2>   else
irb(main):006:2*     n * fact(n - 1)
irb(main):007:2>   end
irb(main):008:1> end
=> :fact
irb(main):009:0> fact(n)
=> 120

irb(main):001:0> class Cat
irb(main):002:1>   def meow
irb(main):003:2>     puts 'The cat meows.'
irb(main):004:2>   end
irb(main):005:1> end
=> :meow

irb(main):006:0> Cat.new.meow
The cat meows.

脚注

  1. ^ All versions of irb”. RubyGems.org. 2025年2月9日閲覧。
  2. ^ naruse (2019年12月25日). “Ruby 2.7.0 リリース”. ruby-lang.org. 2020年7月6日閲覧。

関連項目

外部リンク

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.