Skip to content

Instantly share code, notes, and snippets.

View jack-nie's full-sized avatar
🎯
Focusing

jack-nie

🎯
Focusing
View GitHub Profile
@jack-nie
jack-nie / stacked_middlewares.rake
Created April 9, 2016 09:28 — forked from tyabe/stacked_middlewares.rake
Display lists of all stacked rack middleware for your padrino app
##
# This is rake task of padrino-framework
# Display lists of all stacked rack middleware for your padrino app.
# distributed under the MIT License(http://tyabe.mit-license.org/)
#
def stacked_middlewares(app, args)
require Padrino.root('config/boot.rb')
app_obj = app.app_obj
instance = app_obj.new!
build = app_obj.build(instance)
@jack-nie
jack-nie / array_to_proc.rb
Last active September 10, 2015 05:20 — forked from geowy/array_to_proc.rb
Array#to_proc, shorthand for creating a block that selects elements of an array/hash/collection.
class Array
# Returns a proc which calls [] with the array's contents as arguments
#
# ====Usage
# [[1, 2], [3, 4], [5, 6]].map(&[0])
# # => [1, 3, 5]
#
# [{ hello: 'world' }, { hello: 'sun', goodbye: 'moon' }].map(&[:hello])
# # => ['world', 'sun']
@jack-nie
jack-nie / ova.rb
Last active September 10, 2015 05:20 — forked from 0x0dea/ova.rb
"Real" method overloading in Ruby!
module Ova
# autovivifying map from [class][method][signature] to Method
@@Ova = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
# Wrap #respond_to? for parity with Class#===.
Responder = Struct.new(:method) do
def === obj
obj.respond_to?(method)
end
end