← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 4 of 7

Scripts चलाना

एक Ruby script instructions की एक saved file है जिसे आप एक command से चलाते हैं। यह शुरू से अंत तक एक recipe play करने जैसा है।

In this page:

  1. Scripts चलाना
Syntax
ruby
ruby script_name.rb

Scripts चलाना

एक Ruby script command line से ruby filename.rb से चलती है, हर statement top to bottom execute करते हुए। यह एक complete Ruby program चलाने का standard तरीका है, IRB में interactively experiment करने के उलट।

.rb extension एक convention है, एक strict requirement नहीं।

Note: ruby -c filename.rb बिना actually चलाए एक script की syntax check करता है।

उदाहरण: Running Scripts

bash
# Run a Ruby script from the command line
ruby hello.rb

# Check syntax without running it
ruby -c hello.rb

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. .rb के बिना ruby hello चलाना जब file का नाम hello.rb हो, इसलिए Ruby इसे नहीं ढूंढ पाता।
  2. एक अलग folder से command चलाना, इसलिए Ruby No such file or directory report करता है।
  3. यह भूल जाना कि ruby -c hello.rb सिर्फ syntax check करता है और code चलाता नहीं है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.