Hey Fs,
This page will be quite interesting one. This is the place where you can evaluate yourself. My attempts goes to figure out your basic leanings towards RoR, rather than proving yourself as a Ruby geek or some tech brat.
I will try my best to keep on adding some set of questions with a proper indexing. So keep visiting to evaluate yourself. If you have any questions that you can suggest, please do mail me at infostall@gmail.com.
Thank you & keep enjoying your rides with RoR.
[ QUIZ #1 updated on 08th March 2008 ::::: See Answers#1]
1. "Hello, world!" + 100
2. 100.methods – What is the result
3. Is there any difference between method and function?
4. [100] + ["Hello, world!"] , [“100”] + ["Hello, world!"]
5. What does it return ->
100 if true
6. What’s the o/p?
if(100 if false)
p "hi"
else
p "bye"
end
7. What’s the o/p?
if true
p 100
else
p 50
end
8.In irb window what is significant of digits enclosed between :
irb(main):026:0> def first_if_true(first, second, to_be_tested)
irb(main):027:1> if to_be_tested
irb(main):028:2> first
irb(main):029:2> else
irb(main):030:2* second
irb(main):031:2> end
irb(main):032:1> end
9. o/p?
MYSAL = 30000
MYSAL = MYSAL + 5000
P MYSAL
10. o/p?
MYSAL = 30000
MYSAL = MYSAL.to_s + “hiked by 5000”
P MYSAL
[ Answers of QUIZ #1 :::::::::: Jump Quiz#1]
1. can’t convert Fixnum into String (TypeError)
TypeError is an example of what Ruby (and many other languages) call an
exception,
2. All methods expected on class 100 i.e Fixnum
3. Usually both are used as an interchange. But methods are simply functions which are attached on instances (objects) of a class. Since ruby is purely genuine object oriented language, we must say methods instead using functions.
4. [100,”Hello, world!”], [“100”,”Hello, world!”] – How strong is + operator in Ruby
5. 100
6. bye
7. 100
8. irb(main):030:2* - 30th line number, 2 – the level of inner depth of a block ie. Number for { (start of block)
(similarly number for } in a reverse way) and finally * means incomple, still irb is expecting some codes to be entered.
9. warning: already initialized constant MYSAL
10. “30000 hiked by 5000” –# Tell me how are we able to change the behavior of a constant, while not able to change its value?
[ QUIZ #2 updated on 05th April 2008 ::::See Answers#2]
begin
raise "Error found" if x = 5/0
p "Am I called?"
rescue
print "An error occurred: ",$!, "\n"
ensure
print "I am here"
end
o/p:
a. An error occurred: divided by 0
I am here
b. An error occurred: divided by 0
Error found
I am here
c. Error found
An error occurred: divided by 0
I am here
d. An error occurred: Error found
I am here
[ Answers of QUIZ #2 :::::::::: Jump Quiz#2]
Ans: (a)
Logic: The program terminates as soon as it evaluates x=5/0 and hence go to rescue part and printing the result (a)
The ensure code block executes regardless of the success or failure of the begin block.
[ QUIZ #3 updated on 12th April 2008 ::: See Answers#3]
Its not what you thought, Give a try.
p true and false p true && false p false and true p false && true p true or false p false or true p true || false p false || true
[ Answers of QUIZ #3 :::::::::: Jump Quiz#3]
true, false
false,false
true,false
true,true
What happened???? You mean to say AND and && is different. In the same way OR and || behave in a distinct manner. No.
Still I don’t have a proper answer, except telling that here jack is with “p” or “puts” which always evaluates the very first parameter in case of “and” or “or”. When we use symbolic “&&” / “||” may be some precedence rule, which forces print statement to evaluate by having both operands left and right as well. means
p true && false ==> becomes ===> p (ture && false) , whereas
p true and false ==> becomes ===> p true //takes only one argument.
Please if someone has got a proper answer let me know.
[ QUIZ #4 updated on 16th April 2008 :::::::::: See Answers#4]
a = nil b = "corner" 1. p "Information " + a || b 2. p "Information " + (a || b) 3. p "Information " + b || a 4. p "Information " + a.to_s || b 5. p "Information " + (a.to_s || b)
[ Answers of QUIZ #4 :::::::::: Jump Quiz#4]
1. `+’: can’t convert nil into String (TypeError)
2. “Information corner”
3. “Information corner”
4. “Information “
5. “Information “
+ operator has a higher precedence than ||
so 1 is executed as p (”Information ” + a) || b rather than p “Information ” + (a || b)
Q. 1,4 ::: as + is expecting a string value but a is nil, hence works in case of 4
Q. 2,5 ::: Its the bracket which returns true as b is true in all the cases
Q. 3 ::: b is true hence no problem





