About Me

My photo
जिंदगी की परीक्षा में कोई नम्बर नहीं मिलते है लोग आपको दिल से याद करे तो समझ लेना आप पास हो गए....

Sunday 10 June 2012

Ruby on rails Interview


(1) You are given a file with list of names of 10 people. Write a Ruby program
to print their first names in the sorted order.

Ans:
file = File.open('names_f1','r')
names = []
file.each { |line|
names << line
}

puts names.sort 


(2) Write a short program to print the sum and average of all odd numbers
between 1 and 100.
Ans:

i=1
sum,avg,total_odd =0,0,0

while i<100
unless (i%2 ==0)
sum += i
total_odd +=1
end
i+=1
end

avg = sum/total_odd

puts "sum #{sum}"
puts "Avg #{avg}" 


(3) What is COC and DRY?
Ans:
COC :-CoC means the developer only needs to specify unconventional aspects of application which reduces the code and also repetition.

For example, if there is a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table "products sold” that the developer needs to write code regarding these names.

DRY :-DRY means “don’t repeat yourself” and is a kind of mantra to the rails developers community.
It commonly refers to not using the same (or similar) code in multiple places in your application. Instead, such code should be ‘factored’ out to a common, single location (such as a helper method or partial) and reused in various locations. This results in writing code so that:
  • you only have to do the heavy-lifting once
and
  • you can edit the code in one location and immediately see the changes everywhere.



    (4) On a linux system, how will you know how much RAM it has?
    Ans: free -m

    (5) In a Rails project, which of the three is executed on the client side by
    the browser: Models, Controllers, ERB views?
    Ans : ERB views


    (6)Write a short program to count the number of words in a sentence
    Ans : sentence = " i am a good boy" 
      sentence.split.count
      => 5




      (7) Give an example of a project siutation where you will use polymorphic
association
Ans:


No comments:

Post a Comment