Category: Ruby

Ruby tutorial

Ruby Tutorial – Learn how to use Ruby programming language. Ruby is an object-oriented programming language. The basic topics of Ruby are: variables, strings, methods, blocks, exceptions, arrays, loops and other control statements. Ruby tutorial Ruby Variables Ruby Strings Ruby Date...

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}"...