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 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}"...
Ruby Hashes Ruby Hash is a collection of key-value pairs. The Ruby Hash is created using key-value pair within {}. Hashes syntax myMethod = Hash.new( "myHashName" ) Hashes example myMethod = Hash.new( "myHashName" ) myHashName = {"10" => "A", "20" =>...
Ruby Array The Ruby array is created using the objects between [ and ]. Ruby arrays are ordered collections of elements. Array syntax myArrayName = Array.new Array new class method example myArrayName = Array.new(30) puts myArrayName.size puts myArrayName.length Output 30 30...
Ruby Date and Time The Ruby Date, DateTime and Time examples. Date and Time syntax Date DateTime Time Date and Time example cTime = Time.now puts "Current Time : " + cTime.inspect puts cTime.year puts cTime.month puts cTime.day require 'date' puts...