Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Day1/assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@
# --------------------------------------------------------------------------

# 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
[a,b]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is write but need indentation.

end



# 2. Write any one use case of === operator.
# Your answer here...

This is a case equality operator which is used in versatile range. (1..10) === 3.13455 returns true


# 3. Print array of alphabates using Range operator.
# Your answer here...
('a'..'z').to_a returns all alphabets starting from A to Z.



# 4. Print 'Ho! Ho! Ho! Merry Christmas!' using string interpolation and * operator.
# Your answer here...
a = 'Ho! ' * 3
b = 'Merry Christmas!'

puts a+b



Expand All @@ -29,4 +35,10 @@
# c. Finally, print result in the form
# "Your name is <user's name>"
# "Your age is <user's age>"
# Your answer here...
#

@name = gets
@age = gets

puts "Your name is #{@name}"
puts "Your age is #{@age}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to create another ruby file like test.rb and copy paste this code and check how it works.
It should be print:

What is your name: <your name here>
What is your age   : <your age>

Your name is <your name>.
Your name is <your age>.