Skip to content

Instantly share code, notes, and snippets.

Name Department Manager Salary
Robin Hood 200
Arsene Wenger Bar Friar Tuck 50
Friar Tuck Foo Robin Hood 100
Little John Foo Robin Hood 100
Sam Allardyce 250
Dimi Berbatov Foo Little John 50
# Define the method #each (without using Enumerable#each) so that
# the following prints three lines:
# def each ...
# ...
# end
rgb = ['red', 'blue', 'green']
each(rgb) do |c|
# Use all examples to output the string "Hello, Sven!"
def hello_0(&block)
puts yield
end
def hello_1(&block)
puts block.call
end
# Simple user class
# We're pretending this is an ActiveRecord::Base model
class User
attr_reader :name
def initialize(name)
@name = name
end
end
@joecorcoran
joecorcoran / call.rb
Created February 27, 2017 20:30
call
# Use the method #call on each of these
# examples, to return the value `:hi`
class One
def call
:hi
end
end
class Two
@joecorcoran
joecorcoran / baked_sweet_potatoes.md
Last active November 21, 2016 17:51
Baked sweet potatoes

Baked sweet potatoes

  • 2 large sweet potatoes
  • 250g baby spinach
  • 10 chestnuts
  • 150g goats cheese
  • 2 cloves of garlic
  • Butter/oil
  • Salt/pepper
# Code challenge!
#
# 1. Save the contents of this gist in a
# file named classes.rb
#
# 2. Define the initialize method for class B
# so that, when you run `ruby classes.rb`,
# the output in the terminal is `true`
#
# (Don't define any other methods or

Keybase proof

I hereby claim:

  • I am joecorcoran on github.
  • I am joecorcoran (https://keybase.io/joecorcoran) on keybase.
  • I have a public key ASBxexs-G58IclQz_BXqF5ql0W3WyhYWdPvZQ_iYQe8wdgo

To claim this, I am signing this object:

@joecorcoran
joecorcoran / gist:02217948fa1e80d26b56
Last active June 13, 2016 17:53
Postgresql setup
# In your terminal (Mac OS X):
createuser -s pguser
psql postgres
# In your terminal (Ubuntu):
sudo -u postgres createuser -s pguser
sudo -u postgres psql
@joecorcoran
joecorcoran / keywords.rb
Last active June 13, 2016 10:41
Ruby keyword argument fun
# A weird quirk of keyword args in Ruby that just tripped me up.
# An object passed as the second argument here will be used
# differently depending on its type.
def test(a, b = [], **c)
[a, b, c]
end
# As expected, the default values work.
test(:one) # => [:one, [], {}]
test(:one, :two) # => [:one, :two, {}]