From 82f0d677f7b24b4032150d99630b9904136821e0 Mon Sep 17 00:00:00 2001 From: kkirad Date: Mon, 6 Oct 2014 12:23:17 +0530 Subject: [PATCH 1/2] Done with Day1 Assignment --- Day1/assignment.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Day1/assignment.rb b/Day1/assignment.rb index 2d1ce5d..4197992 100644 --- a/Day1/assignment.rb +++ b/Day1/assignment.rb @@ -2,25 +2,32 @@ # -------------------------------------------------------------------------- # 1. Write a method to swap two variables. -# def method(a, b) -# Your code here.... +def swap_num(a,b) + temp=a + a=b + b=temp + puts a + puts b + end # end # 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! Ho! Ho! Merry Christmas!" +puts "#{str}" # 5. Write a ruby program that perform following operations: @@ -30,3 +37,9 @@ # "Your name is " # "Your age is " # Your answer here... +puts "Enter your name" +name= gets +puts "Enter your age" +age=gets +puts "Your name is #{name}" +puts "Your age is #{age}" From 31d7d1825fd5083f43c560d11ad6334c7252bee8 Mon Sep 17 00:00:00 2001 From: kkirad Date: Mon, 13 Oct 2014 11:16:46 +0530 Subject: [PATCH 2/2] Assigment of Day1 completed --- Day1/assignment.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Day1/assignment.rb b/Day1/assignment.rb index 4197992..be54dc1 100644 --- a/Day1/assignment.rb +++ b/Day1/assignment.rb @@ -1,16 +1,14 @@ # Day 1 : Assignments # -------------------------------------------------------------------------- -# 1. Write a method to swap two variables. -def swap_num(a,b) - temp=a - a=b - b=temp - puts a - puts b - end -# 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. @@ -26,8 +24,9 @@ def swap_num(a,b) # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. # Your answer here... -str="Ho! Ho! Ho! Merry Christmas!" -puts "#{str}" +str = 'Ho! ' * 3 +print "#{str} Merry Christmas!" + # 5. Write a ruby program that perform following operations: @@ -37,9 +36,10 @@ def swap_num(a,b) # "Your name is " # "Your age is " # Your answer here... -puts "Enter your name" -name= gets -puts "Enter your age" -age=gets +print 'Enter your name: ' +name = gets +print 'Enter your age: ' +age = gets puts "Your name is #{name}" puts "Your age is #{age}" +