diff --git a/Day1/assignment.rb b/Day1/assignment.rb index 2d1ce5d..be54dc1 100644 --- a/Day1/assignment.rb +++ b/Day1/assignment.rb @@ -1,25 +1,31 @@ # Day 1 : Assignments # -------------------------------------------------------------------------- -# 1. Write a method to swap two variables. -# def method(a, b) -# Your code here.... -# end - +# 1. Write a method to swap two variables. +def swap(a, b) + a += b + b = a - b + a -= b + puts "a = #{a} b = #{b}" + end +swap(3, 5) # 2. Write any one use case of === operator. # Your answer here... - - +It can used to check equality. +EG: (1...10)==3 returns true # 3. Print array of alphabates using Range operator. # Your answer here... +alphabets=Array('a'..'z') # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. # Your answer here... +str = 'Ho! ' * 3 +print "#{str} Merry Christmas!" @@ -30,3 +36,10 @@ # "Your name is " # "Your age is " # Your answer here... +print 'Enter your name: ' +name = gets +print 'Enter your age: ' +age = gets +puts "Your name is #{name}" +puts "Your age is #{age}" +