This file contains hidden or 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 'login_management' | |
use Rack::Session::Cookie | |
use Warden::Manager do |manager| | |
manager.default_strategies :password | |
manager.failure_app = LoginManager | |
end | |
run LoginManager |
This file contains hidden or 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
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 } |
This file contains hidden or 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
# 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, |
This file contains hidden or 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
# ===================== | |
# Spell: Symbol to Proc | |
# ===================== | |
# Convert a symbol to a block that calls a single method. | |
[1, 2, 3, 4].map(&:even?) # => [false, true, false, true] | |
# For more information: http://www.pragprog.com/titles/ppmetr/metaprogramming-ruby |
This file contains hidden or 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
# ===================== | |
# 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 |
This file contains hidden or 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
# ======================= | |
# Spell: Singleton Method | |
# ======================= | |
# Define a method on a single object. | |
obj = "abc" | |
class << obj | |
def my_singleton_method |
This file contains hidden or 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
# ================= | |
# Spell: Self Yield | |
# ================= | |
# Pass self to the current block. | |
class Person | |
attr_accessor :name, :surname | |
def initialize |
This file contains hidden or 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
# ================= | |
# Spell: Scope Gate | |
# ================= | |
# Isolate a scope with the class, module, or def keyword. | |
a = 1 | |
defined? a # => "local-variable" | |
module MyModule |
This file contains hidden or 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
# ============== | |
# Spell: Sandbox | |
# ============== | |
# Execute untrusted code in a safe environment. | |
def sandbox(&code) | |
proc { | |
$SAFE = 2 | |
yield |
OlderNewer