1. Home
  2. /
  3. Ruby
  4. /
  5. File Handling

File Handling - Ruby Typing CST Test

Loading…

File Handling — Ruby Code

Shows how to read and write files in Ruby safely using blocks.

File.open("example.txt", "w") do |file|
	file.puts "This is a sample text file."
	file.puts "Written with Ruby!"
end

puts "File written successfully."

puts "Reading file contents:"
File.readlines("example.txt").each_with_index do |line, index|
	puts "#{index + 1}: #{line.strip}"
end

Ruby Language Guide

Ruby is a dynamic, object-oriented, high-level programming language designed for simplicity, productivity, and readability. It emphasizes developer happiness and convention over configuration, widely used for web development, scripting, automation, and backend systems.

Primary Use Cases

  • ▸Web application development (Ruby on Rails, Sinatra)
  • ▸Backend APIs and microservices
  • ▸Automation and scripting
  • ▸Prototyping and MVPs
  • ▸DevOps tooling (Chef, Puppet)
  • ▸Data processing scripts

Notable Features

  • ▸Everything is an object
  • ▸Dynamic typing and duck typing
  • ▸Powerful metaprogramming and DSL support
  • ▸Elegant and readable syntax
  • ▸Convention over configuration (Rails)
  • ▸Large ecosystem and gems library

Origin & Creator

Created by Yukihiro 'Matz' Matsumoto in 1995 in Japan. Designed to maximize developer happiness by blending Perl, Smalltalk, Eiffel, Ada, and Lisp influences into an elegant, readable syntax.

Industrial Note

Ruby dominates web startups, SaaS platforms, rapid prototyping, automation, and DevOps tooling (Chef, Puppet). Ruby on Rails accelerates development, making it a top choice for MVPs and web platforms like GitHub, Shopify, and Basecamp.

More Ruby Typing Exercises

Ruby Blocks and IteratorsRuby Classes and InheritanceRuby Modules and MixinsRuby Exception HandlingRuby Hashes and SymbolsRuby Regular ExpressionsRuby Enumerables and MapRuby JSON ParsingRuby Time and Date Formatting

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#MqlCqlN1qlCypherGremlin