Ruby interview questions part 8

Ruby interview questions part 8

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Why is the library function ‘puts’used for?

Correct Answer is : Prints whatever is given and insert a new(blank) line

2. What is the output of the given code? print "Hey" puts "Everyone!" print "We are learning Ruby"

Correct Answer is : Hey Everyone

3. We use semicolon or parentheses after every print or puts statement.

Correct Answer is : FALSE

4. For getting an input from the user which method is used?

Correct Answer is : gets.chomp

5. What is the output of given code? puts "what is your first name?" name=gets.chomp puts "what is your surname?" surname=gets.chomp

Correct Answer is : What is your first name?

6. Which sequence can be used to substitute the value of any ruby expression in a string?

Correct Answer is : #{expr}

7. Why is gets not preferred instead of gets.chomp?

Correct Answer is : Gets add an extra new line while chomp removes it

8. first_name,Last_name=gets.chomp,gets.chomp is the correct way to get the input from the user.

Correct Answer is : TRUE

9. What is the output of the given code? print "What's your address" city,state,pin=gets.chomp,gets.chomp,gets.chomp puts "Iam from #{city} city, #{state} state, pincode: #{pin} "

Correct Answer is : What’s your address? Chennai

10. What is the output of the the given code? puts "My name is #{Name}"

Correct Answer is : Name variable not defined earlier

11. What is the output of the given code? Ans=Ruby puts "#{Ans} is an oop language" puts "It is very efficient langauge" puts "#{expr} is used on rails platform"

Correct Answer is : Ruby is an oop language

12. What is the output of the given code? Ans=Ruby puts "#[Ans] is an oop language"

Correct Answer is : Ruby is an oop language

13. Boolean opeartors are also known as logical operators.

Correct Answer is : TRUE

14. Which of the following is a valid boolean operator?

Correct Answer is : All of the mentioned

15. The boolean operator && only result in true when both the values are true?

Correct Answer is : TRUE

16. What will the following expression evaluate to? true && false

Correct Answer is : FALSE

17. What will be the output of the given code? boolean_1 = 77 < 78 && 77 < 77 puts boolean_1

Correct Answer is : FALSE

18. What will the following expression evaluate to? true || false

Correct Answer is : TRUE

19. What will the following expression evaluate to? (true && false) || (!true)

Correct Answer is : FALSE

20. What will the following expression evaluate to? !true && !false

Correct Answer is : FALSE

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon