Category: Ruby

Ruby tutorial

Ruby is a dynamic, object-oriented programming language known for its simplicity and elegance. Developed by Yukihiro Matsumoto in the mid-1990s, Ruby was designed to be both enjoyable for programmers and highly productive. It combines elements from several programming languages, including Perl,...

Ruby Exceptions

Ruby Exceptions The Ruby exceptions syntax and example. Exceptions syntax begin --Ruby code rescue --Ruby code end Exceptions example begin puts 'Start block' raise 'Raise Error!' puts 'End block' rescue puts 'Exception Handling with rescue' begin puts 'Block in exception' end...

Ruby Blocks

Ruby Blocks The Ruby blocks syntax and example. Blocks syntax block_name{ -- Ruby code } --or do -- Ruby code end Blocks example def test_block puts "Method A" yield puts "Method B" yield 123 puts "Method C" yield "abc" end test_block...

Ruby Methods

Ruby Methods The Ruby methods syntax and example. A Ruby method consists of: The def keyword Method name The body of the method Return value The end keyword Methods syntax def method_name -- Ruby code end --or def method_name(value_1, value_2) --...

Ruby Ranges

Ruby Ranges The Ruby range represents an interval of values. The syntax of Ruby range allow you to include or exclude its ending value. Ranges syntax (1..10) (1...10) Ranges example r1 = (1..5).to_a r2 = (1...5).to_a r3 = (1..5).to_a.reverse puts "#{r1}"...