Skip to content

Instantly share code, notes, and snippets.

require 'login_management'
use Rack::Session::Cookie
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = LoginManager
end
run LoginManager
class MyApplication < Sinatra::Base
use Rack::Session::Cookie
use Warden::Manager do |manager|
manager.default_strategies :password
manager.failure_app = MyApplication
end
Warden::Manager.serialize_into_session{ |user| user.id }
@zzak
zzak / lisp.rb
Created September 5, 2010 16:20 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong MinHee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
# =======================
# Spell: Object Extension
# =======================
# Define Singleton Methods by mixing a module into an object’s eigenclass.
obj = Object.new
module M
def my_method
# =======================
# Spell: Singleton Method
# =======================
# Define a method on a single object.
obj = "abc"
class << obj
def my_singleton_method
@zzak
zzak / monkeypatch.rb
Created September 13, 2010 16:53 — forked from nusco/monkeypatch.rb
# ==================
# Spell: Monkeypatch
# ==================
# Change the features of an existing class.
"abc".reverse # => "cba"
class String
def reverse
# =====================
# Spell: String of Code
# =====================
# Evaluate a string of Ruby code.
my_string_of_code = "1 + 1"
eval(my_string_of_code) # => 2
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby
# =============================
# Spell: Lazy Instance Variable
# =============================
# Wait until the first access to initialize an instance variable.
class C
def attribute
@attribute = @attribute || "some value"
end
# ======================
# Spell: Named Arguments
# ======================
# Collect method arguments into a hash to identify them by name.
def my_method(args)
args[:arg2]
end
@zzak
zzak / hook_method.rb
Created September 13, 2010 16:53 — forked from nusco/hook_method.rb
# ==================
# Spell: Hook Method
# ==================
# Override a method to intercept object model events.
$INHERITORS = []
class C
def self.inherited(subclass)