Last active
December 15, 2015 13:29
-
-
Save bkerley/5268037 to your computer and use it in GitHub Desktop.
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
2.0.0-p0 |
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
require 'pp' | |
def r | |
begin | |
yield | |
rescue => e | |
puts | |
pp e | |
end | |
end | |
def none | |
puts | |
puts "called with no arguments" | |
end | |
none | |
def one(x) | |
puts | |
print "called with: " | |
pp x | |
end | |
one "hello" | |
def two(x, y) | |
one x | |
print "and " | |
pp y | |
end | |
two "hello", "goodbye" | |
def kw(x, y: "default y") | |
one x | |
print "and y=" | |
pp y | |
end | |
kw "hello", y: "hasta la vista" | |
r { kw "oops" } | |
r { kw "hello", "friends" } | |
r { kw an: 'implicit hash', y: 'because' } | |
def opt(x, y="optional") | |
one x | |
print "optional keyword is " | |
pp y | |
end | |
opt "okay" | |
opt "okay", "computer" | |
opt "okay", lets: 'do it' | |
def example(id, order: 'id asc', where: {}, limit: 1) | |
puts | |
puts "hypothetical activerecord!" | |
puts "id: #{id.inspect}, order: #{order.inspect}," | |
puts "where: #{where.inspect}, limit: #{limit.inspect}" | |
end | |
example 5 | |
example :all, order: 'name desc' | |
example :all, limit: 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment