Skip to content

Instantly share code, notes, and snippets.

@peterhurford peterhurford/

Last active Aug 29, 2015
What would you like to do?
Rails Interview

1a.) Why would one use a symbol instead of a string?

1b.) Why would someone use a string instead of a symbol?

2a.) What is the difference between a lambda, a block and a proc?

2b.) What does -> (a) {p a}["Hello world"] do?

3.) If x = "hello", what is the difference between x += " world" and x.concat "world"?

4a.) 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 }


def count_strings(arr)

4b.) In Ruby code, you quite often see the trick of using an expression like as a shorthand form of { |element| element.method_name }. How exactly does it work?


VAL = 'Global'
module Foo
  VAL = 'Foo Local'
  class Bar
    def value1
      puts VAL
class Foo::Bar
  def value2
    puts VAL

What will be the value of each of the following: and


val1 = true and false
val2 = true && false

What is val1? What is val2? Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.