Skip to content

Instantly share code, notes, and snippets.

@dbtlr
dbtlr / webrick.rb
Created July 25, 2012 19:51
WEBrick command line server
#!/usr/bin/ruby
require 'webrick'
require 'optparse'
options = { :port => 4000, :host => 'localhost', :root => '.' }
OptionParser.new do |opts|
opts.banner = "Usage: webrick.rb [options]"
opts.on("-p", "--port [port]", "Set the port to use, defaults to 4000.") do |p|
@mislav
mislav / procs-vs-lambda.md
Last active March 26, 2021 18:34
Jim Weirich on the differences between procs and lambdas in Ruby

Jim Weirich:

This is how I explain it… Ruby has Procs and Lambdas. Procs are created with Proc.new { }, lambdas are created with lambda {} and ->() {}.

In Ruby 1.8, proc {} creates lambda, and Ruby 1.9 it creates procs (don't ask).

Lambdas use method semantics when handling parameters, procs use assignment semantics when handling parameters.

This means lambdas, like methods, will raise an ArgumentError when called with fewer arguments than they were defined with. Procs will simply assign nil to variables for arguments that were not passed in.

@christhekeele
christhekeele / ecto_adapter_custom.ex
Last active August 31, 2018 08:42
Scaffold for a full implementation of the Ecto Adapter behaviours. (Ecto v2.1.4)
defmodule Ecto.Adapter.Custom do
####
# Ecto.Adapter
##
# TYPES
# @type t :: Ecto.Adapter.t
@type t :: Ecto.Adapter.Custom