Skip to content

Instantly share code, notes, and snippets.

@bkerley
Last active December 15, 2015 13:29
Show Gist options
  • Save bkerley/5268037 to your computer and use it in GitHub Desktop.
Save bkerley/5268037 to your computer and use it in GitHub Desktop.
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