Category: Ruby

Ruby Hashes

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

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

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

Ruby Strings

Ruby Strings The Ruby strings syntax and example. Strings syntax puts "This is a string." puts 'String syntax' Strings example puts "This is a string." puts 'String syntax' puts "abc - 123" puts "1234567" puts "Concatenate string A" + "BCDE" puts...

Ruby Variables

Ruby Variables The Ruby Variables syntax and examples. Local Variables syntax Local Variables variable_name = variable_value Global Variables $variable_name = variable_value Class Variables Instance Variables Local Variables example irb(main):001:0> x=1 => 1 irb(main):002:0> x => 1 irb(main):003:0> Variables example x=1 puts...