From 8a7f368d61dc07d789ed6fdbd07472076562a63f Mon Sep 17 00:00:00 2001 From: BasvrajSutagatti Date: Tue, 7 Oct 2014 18:00:26 +0530 Subject: [PATCH] Assignment 1 submitted --- Day1/assignment.rb | 55 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/Day1/assignment.rb b/Day1/assignment.rb index 2d1ce5d..560b2ca 100644 --- a/Day1/assignment.rb +++ b/Day1/assignment.rb @@ -2,25 +2,41 @@ # -------------------------------------------------------------------------- # 1. Write a method to swap two variables. -# def method(a, b) -# Your code here.... -# end - + def swap(a,b) + a=a+b + b=a-b + a=a-b + puts "a=#{a} b=#{b}" + end + swap(10,20) + # 2. Write any one use case of === operator. -# Your answer here... + + (1..10)===10.00 + => true + (1..10)===10.01 + => false -# 3. Print array of alphabates using Range operator. -# Your answer here... +# 3. Print array of alphabate using Range operator. + ('a'..'z').to_a + ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] # 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator. -# Your answer here... - + a='Ho! '*3 + "Ho! Ho! Ho! " + b='Merry Christmas' + "Merry Christmas" + a+b + "Ho! Ho! Ho! Merry Christmas" + puts a+b + Ho! Ho! Ho! Merry Christmas # 5. Write a ruby program that perform following operations: @@ -29,4 +45,23 @@ # c. Finally, print result in the form # "Your name is " # "Your age is " -# Your answer here... + + Ans + def personinfo() + a="What is your name" + puts a + name=gets.chomp + b="What is your age?" + puts b + age=gets + puts "Your name is "+name+" and your age is "+age + end + /*output*/ + What is your name + Raj + What is your age + 25 + Your name is Raj and your age is 25 + + +