Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Ruby Interview Questions (No Rails, for a Prospective Junior Developer / Intern)

What does a ||= b mean?

What is the difference between a symbol and a string?

What is the difference between ' and " in Ruby?

Can you give me a function that takes a string and tells me true or false if it has any characters in it?

def empty?(s)
  s.size == 0

Can you give me a function that takes as its input an array of any number of strings and gives as its output an array with the number of characters in each string of the input array?

def count_strings(arr) { |str| str.length }

Extra credit: Difference between map and map!. Other ruby enumerables.

What is the difference between a class and a module?

What are the differences between public, private, and protected methods?

Extra credit: How, in Ruby, can you call a private method without being that instantiated class?

Can you make a Ruby class that represents a bank account, with methods to withdraw and deposit money?

class BankAccount
  def initialize
    @balance = 0
  def deposit(amount)
    @balance += amount
  def withdraw(amount)
    @balance -= amount

Extra credit: How can you, in one line, create a method to write and read to the balance? (attr_accessor :account)

How would you test Ruby code?

Copy link

Yorgg commented May 22, 2015

Wouldn't instance methods be required for the last question so that new bankaccount objects could call the deposit, and withdraw methods?

Joe =

Copy link

peterhurford commented Jun 22, 2015

@Yorgg: Yep, I was wrong to make them class methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment