- 2 large sweet potatoes
- 250g baby spinach
- 10 chestnuts
- 150g goats cheese
- 2 cloves of garlic
- Butter/oil
- Salt/pepper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use all examples to output the string "Hello, Sven!" | |
def hello_0(&block) | |
puts yield | |
end | |
def hello_1(&block) | |
puts block.call | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple user class | |
# We're pretending this is an ActiveRecord::Base model | |
class User | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the method #call on each of these | |
# examples, to return the value `:hi` | |
class One | |
def call | |
:hi | |
end | |
end | |
class Two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, {}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin |
NewerOlder