Ruby On Rails Interview Questions Part-1
1.1 What is Ruby?
Ruby is a pure object-oriented programming language with a super clean syntax that makes programming elegant and fun. Ruby successfully combines Smalltalk's conceptual elegance, Python's ease of use and learning, and Perl's pragmatism. Ruby originated in Japan in the early 1990s, and has started to become popular worldwide in the past few years as more English language books and documentation have become available.
1.2 What is Rails?
Rails is an open source Ruby framework for developing database-backed web applications. What's special about that? There are dozens of frameworks out there and most of them have been around much longer than Rails. Why should you care about yet another framework? What would you think if I told you that you could develop a web application at least ten times faster with Rails than you could with a typical Java framework? You can--without making any sacrifices in the quality of your application! How is this possible? Part of the answer is in the Ruby programming language. Many things that are very simple to do in Ruby are not even possible in most other languages. Rails takes full advantage of this. The rest of the answer is in two of Rail's guiding principles: less software and convention over configuration. Less software means you write fewer lines of code to implement your application. Keeping your code small means faster development and fewer bugs, which makes your code easier to understand, maintain, and enhance. Very shortly, you will see how Rails cuts your code burden. Convention over configuration means an end to verbose XML configuration files--there aren't any in Rails! Instead of configuration files, a Rails application uses a few simple programming conventions that allow it to figure out everything through reflection and discovery. Your application code and your running database already contain everything that Rails needs to know!
1.3 How to capitalize UTF8 string without downcasing
What is the best way to capitalize the first character of a UTF8 string? String#capitalize downcases the rest of the string which is unacceptable since there can be capitals in the middle of the string. ("see New York".capitalize => "See new york"). Just picking off the first byte and capitalizing that is also not an option since the first character can be a multibyte UTF-8 character. The only thing I can think of so far is either using Ruby 1.9 or the the Rails multibyte Chars library to split off the first character and then capitalize that and join it back together. Surely there must be a better way for such a common problem?
1.4 What is the naming conventions for methods that return a boolean result?
Methods that return a boolean result are typically named with a ending question mark. For example: def active? return true #just always returning true end
1.5 What are the object-oriented programming features supported by Ruby?
Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and overloading) are some oo concepts supported by ruby. ...
1.6 What are the operating systems supported by Ruby?
Windows and linux operating systems are supported by the Ruby
1.7 Whats the difference between symbol and string?
Symbol refers to the same memory location where string generates a new id every time for eg.
STRING irb(main):019:0> "ruby".object_id > 24095860 irb(main):020:0> "ruby".object_id > 24092310 irb(main):021:0> "ruby".object_id > 24088760 irb(main):022:0> SYMBOL irb(main):022:0> :ruby.object_id > 102978 irb(main):023:0> :ruby.object_id > 102978 irb(main):024:0> :ruby.object_id > 102978 irb(main):025:0> :ruby.object_id > 102978 irb(main):026:0>
1.8 How do you comment out a block of code?
Use =begin and =end. =begin def
my_commented_out_method end =end You could use successive # signs, but that's just tedious: # # def my commented_out_method # end #
1.9 How would you create a new ruby rail application?
To create a new ruby rail application rails my_app cd my_app
1.10 What is the difference between nil and false in ruby?
False is a boolean datatype Nil is not a data type
1.11 What two delimiters are used for blocks?
Curly braces {...} and "do"..."end" Bonus: coding convention is to use curly braces if the code will fit on one line and "do"..."end" syntax if the block contains multiple lines.
1.12 What is the naming conventions for methods that return a boolean result?
Methods that return a boolean result are typically named with a ending question mark. For example: def active? return true #just always returning true end
1.13 Explain about the programming language ruby?
Ruby is the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable. Oh, I need to mention, it's totally free, which means not only free of charge, but also freedom to use, copy, modify, and distribute it.
Features of Ruby * Ruby has simple syntax, partially inspired by Eiffel and Ada. * Ruby has exception handling features, like Java or Python, to make it easy to handle errors. * Ruby's operators are syntax sugar for the methods. You can redefine them easily. * Ruby is a complete, full, pure object oriented language: OOL. This means all data in Ruby is an object, in the sense of Smalltalk: no exceptions. Example: In Ruby, the number 1 is an instance of class Fixnum. * Ruby's OO is carefully designed to be both complete and open for improvements. Example: Ruby has the ability to add methods to a class, or even to an instance during runtime. So, if needed, an instance of one class *can* behave differently from other instances of the same class. * Ruby features single inheritance only, *on purpose*. But Ruby knows the concept of modules (called Categories in Objective-C). Modules are collections of methods. Every class can import a module and so gets all its methods for free. Some of us think that this is a much clearer way than multiple inheritance, which is complex, and not used very often compared with single inheritance (don't count C++ here, as it has often no other choice due to strong type checking!). * Ruby features true closures. Not just unnamed function, but with present variable bindings. * Ruby features blocks in its syntax (code surrounded by '{' ... '}' or 'do' ... 'end'). These blocks can be passed to methods, or converted into closures. * Ruby features a true mark-and-sweep garbage collector. It works with all Ruby objects. You don't have to care about maintaining reference counts in extension libraries. This is better for your health. ;-) * Writing C extensions in Ruby is easier than in Perl or Python, due partly to the garbage collector, and partly to the fine extension API. SWIG interface is also available. * Integers in Ruby can (and should) be used without counting their internal representation. There *are* small integers (instances of class Fixnum) and large integers (Bignum), but you need not worry over which one is used currently. If a value is small enough, an integer is a Fixnum, otherwise it is a Bignum. Conversion occurs automatically. * Ruby needs no variable declarations. It uses simple naming conventions to denote the scope of variables. Examples: simple 'var' = local variable, '@var' = instance variable, '$var' = global variable. So it is also not necessary to use a tiresome 'self.' prepended to every instance member. * Ruby can load extension libraries dynamically if an OS allows. * Ruby features OS independent threading. Thus, for all platforms on which Ruby runs, you also have multithreading, regardless of if the OS supports it or not, even on MS-DOS! ;-) * Ruby is highly portable: it is developed mostly on Linux, but works on many types of UNIX, DOS, Windows 95/98/Me/NT/2000/XP, MacOS, BeOS, OS/2, etc. 1.14 Why Ruby on Rails? 1)for fast developing websites 2)convention over configuration 3)scaffolding 4)pure Object oriented concepts 5)less coding 6)easy understanding of coding 7)follows MVC architecture 8)using library and gem files