GeekInterview.com
Series: Subject: Topic:

Ruby Interview Questions

Showing Questions 1 - 20 of 22 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

What are the ways of executing a block from an iterator method?

Asked By: nehalshah | Asked On: Mar 25th, 2007

Answered by: karmue on: Apr 1st, 2013

when you can finish your code in one line, use {|x| ..... }
when you have multiple lines in a blocki, use
do |x|
....
end

Answered by: Manu sharma on: Sep 21st, 2012

Iterate and a block through an array :-

presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"]
presidents.each {|pres| puts pres}

OR

#The block neednt be on one line:

presidents = ["Ford", "Carter", "Reagan", "Bush1", "Clinton", "Bush2"]
presidents.each {
|pres|
puts pres
}

What are the editors supported by ruby?

Asked By: Robert | Asked On: Mar 25th, 2007

Answered by: karmue on: Apr 1st, 2013

vim for editing
rubymine for general developing

Answered by: Sergey on: Feb 18th, 2012

Do not forget about TextMate :-)

What are the looping structures available in ruby?

Asked By: StephenRaj | Asked On: Mar 25th, 2007

Answered by: karmue on: Apr 1st, 2013

and this one

10.times do {|x| puts x}

Answered by: Satya on: Mar 11th, 2013

for loop while loop until loop do..end is not a loop(it is alternate form of defining a block)

Code
  1. count = 0
  2. while count < 5 do
  3.         puts count
  4.         count += 1
  5. end
  6.  
  7. for i in 0..4 do
  8.         puts i
  9. end
  10.  
  11. y = 4
  12. until y < 0 do
  13.         puts y
  14.         y -= 1
  15. end

What is a class instance variable?

Asked By: scott | Asked On: Mar 25th, 2007

Answered by: karmue on: Apr 1st, 2013

there's no class instance variable but there is instance variable and class variable, or global variable @variable is shared in the defined instance

@@variable is shared for all instances of this class
and also you need attr_accessor to enable access from outside

Answered by: Satya on: Mar 11th, 2013

There is nothing called Class instance variables but there are Class variables that are shared by all the instances of a Class. Every Class variable is declared preceded by @@.

Code
  1. class SomeClass
  2.         @@no_of_instances = 0
  3.         .....
  4.         ...
  5.         ..
  6. end

What is the use of super?

Asked By: sripri | Asked On: Mar 25th, 2007

Answered by: Satya on: Mar 11th, 2013

super is used to call the parent classes initialize method from the childs initialize method. super has following forms of implementation. 1. Calling only the super means, call the parents initialize ...

Answered by: Santhiya on: Aug 8th, 2007

Use the super keyword to call the superclass implementation of the current method.

Should we prefer ruby over PHP? If yes why?

Asked By: Tarique A.K. | Asked On: Jan 29th, 2007

Answered by: vijaysrinivas on: Feb 8th, 2013

Ruby is simple to use and flexible for object oriented and functional oriented

What are the operating systems supported by ruby?

Asked By: nehalshah | Asked On: Mar 25th, 2007

Answered by: Maruthi M G on: Apr 16th, 2012

Mac Os, Windows, Linux

Answered by: Ayyappan K on: Sep 21st, 2007

Ruby is supported by windows and linux.

What are the rules and conventions to be followed in ruby for naming a method?

Asked By: sripri | Asked On: Mar 25th, 2007

Answered by: Christopher Kleeschulte on: Feb 13th, 2012

According to Martin Fowler, http://martinfowler.com/bliki/ClassInstanceVariable.html, A Class Instance Variable is a class-level variable that DOES NOT get inherited in any of the subclasses like a cl...

Answered by: hari on: Feb 3rd, 2012

method should start with small letter.If the method name contain two words use underscore to separate the words
ex:get_name

What is the use of :var in ruby?

Asked By: StephenRaj | Asked On: Mar 25th, 2007

Answered by: vijay prasad on: Jul 22nd, 2011

In Ruby the :var is used to define a symbol. A symbol ii ruby is created by adding 'colon' in-front of variable name .You can also create symbol by transforming a string to symbol using string#inte...

Answered by: gikie on: Dec 14th, 2009

:var : Semicolon followed by an identifier tells us that var is symbol.Two strings with same content may belong to two totally different objetcs but if you convert these two strings to symbol, both of...

How does nil and false differ?

Asked By: nancyphilips | Asked On: Mar 25th, 2007

Answered by: africangal on: Mar 23rd, 2010

FALSE is a Boolean data type while NIL is not a data type.

Answered by: kalyan.allampalli on: May 19th, 2009

In Ruby nil is an Object for NilClass,

You can directly check as nil.classit will return NilClass.

Where as false is an object for FalseClass.

Using two databases to a single application

Asked By: suganyaRamesh | Asked On: May 2nd, 2008

How to use two databases to a single application?

Answered by: ericfeng on: Sep 30th, 2009

This is for Ruby on Rails.1. Set the database at config/database.yml. ex mydb:    adapter: mysql    database: mydb    socket: /tmp/mysql.sock  &n...

What is the use of destructive method?

Asked By: RyanJames | Asked On: Mar 26th, 2007

Answered by: javierisassi on: Jun 25th, 2009

It is a method that alters the attribute of an object.myabcs = ['a', 'b', 'c']#myabcs is of type Array.myabcs.reverse!# this method altered the object.p myabcs#outputs:#["...

What is the use of GLobal variable $ in ruby?

Asked By: nancyphilips | Asked On: Mar 25th, 2007

Answered by: kalyan.allampalli on: May 19th, 2009

A Global variable ($a) has a full scope in application. We can use any where in the application as you want.

Answered by: Manikandan Mca on: Aug 18th, 2007

If you declare one variable as global we can access any where, where as class variable visibility only in the class Exampleclass Testdef h  $a = 5  @b = 4 while $a > 0puts $a$a= $a - 1endendendtes...

What are the operators available in ruby?

Asked By: StephenRaj | Asked On: Mar 25th, 2007

Answered by: frikshun on: Aug 13th, 2008

Don't forget the funky ones like a <=>  b, which returns 1 if a > b, 0 if a = b and -1 if a < b.

Answered by: natchiar on: Aug 17th, 2007

Something thats used in an expression to manipulate objects such as + (plus), - (minus), * (multiply), and / (divide). You can also use operators to do comparisons,such as with <, >, and &&.

How is visibility of methods changed in ruby?

Asked By: scott | Asked On: Mar 25th, 2007

Answered by: m_bhupendrain on: Jun 21st, 2008

By applying the access modifier : Public , Private and Protected acces Modifier

What are the object-oriented programming features supported by ruby?

Asked By: nehalshah | Asked On: Mar 25th, 2007

Answered by: Ayyappan K on: Sep 21st, 2007

Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and  overloading) are some oo concepts  supported by ruby.

How is an iterator handled in ruby?

Asked By: Robert | Asked On: Mar 25th, 2007

Answered by: Ayyappan K on: Sep 21st, 2007

Iterator is handled using keyword 'each' in ruby.
For example
$no=[1,2,3]
then we can use iterator as
$no.each do |l|
puts l
end
Above prints the values of an array $no which is accomplished using iterator.

What is the scope of a local variable in ruby?

Asked By: Robert | Asked On: Mar 25th, 2007

Answered by: natchiar on: Aug 17th, 2007

A new scope for a local variable is introduced in the toplevel, a class (module) definition, a method defintion. In a procedure block a new scope is introduced but you can access to a local variabl...

What is the use of load and require in ruby?

Asked By: nancyphilips | Asked On: Mar 25th, 2007

Answered by: natchiar on: Aug 17th, 2007

A method that loads and processes the Ruby code from a separate file, including whatever classes, modules, methods, and constants are in that file into the current scope. load is similar, but rather than performing the inclusion operation once, it reprocesses the code every time load is called.

How is class methods defined in ruby?

Asked By: sripri | Asked On: Mar 25th, 2007

Answered by: natchi on: Aug 17th, 2007

def self.methodname
--------
--------
end

or
def classname.methodname
--------
--------
end

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.