ruby interview questions
Top ruby frequently asked interview questions
How can I check whether a variable is defined in Ruby? Is there an isset
-type method available?
Source: (StackOverflow)
Is there a quick way to find every match of a regular expression in Ruby? I've looked through the Regex object in the Ruby STL and searched on Google to no avail.
Source: (StackOverflow)
In C and many other languages, there is a continue
keyword that, when used inside of a loop, jumps to the next iteration of the loop. Is there any equivalent of this continue
keyword in Ruby?
Source: (StackOverflow)
Ruby has this handy and convenient way to share instance variables by using keys like
attr_accessor :var
attr_reader :var
attr_writer :var
Why would I choose attr_reader
or attr_writer
if I could simply use attr_accessor
? Is there something like performance (which I doubt)? I guess there is a reason, otherwise they wouldn't have made such keys.
Source: (StackOverflow)
I've got a rake task that I am making that needs to insert a value into multiple databases.
I'd like to be able to pass this value into the rake task from the command line, or from another rake task, how can I do this?
Source: (StackOverflow)
I just updated to rails 4.0.2 and I'm getting this warning:
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Is there any security issue in setting it to false?
Source: (StackOverflow)
Since upgrading to Rails 3.1 I'm seeing this warning message in my development log:
WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
What does this mean and how can I remove it? Is it a problem?
Source: (StackOverflow)
I don't use the RI or RDoc output from the gems I install in my machine or in the servers I handle (I use other means of documentation).
Every gem I install installs RI and RDoc documentation by default, because I forget to set --no-ri --no-rdoc
.
Is there a way to make those two flags the default?
Source: (StackOverflow)
I am having some problems when trying to install mysql2
gem for Rails. When I try to install it by running bundle install
or gem install mysql2
it gives me the following error:
Error installing mysql2: ERROR: Failed to build gem native extension.
How can I fix this and successfully install mysql2
?
Source: (StackOverflow)
I have an array of integers.
For example:
array = [123,321,12389]
Is there any nice way to get the sum of them?
I know, that
sum = 0
array.each { |a| sum+=a }
would work.
Source: (StackOverflow)
I have a value 'Dog'
and an array ['Cat', 'Dog', 'Bird']
.
How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more?
Source: (StackOverflow)