Skip to content

Instantly share code, notes, and snippets.

@chischaschos
chischaschos / aliasing.rb
Created November 15, 2010 16:07
rubylearning.org - metaprogramming - method wrapper
module RubyLearning
module Module
WRAPPER_PREFIX = 'wrapper_'
WRAPPED_PREFIX = 'wrapped_'
def before(method, prev_option = {})
prev_option.merge!(:before => normalize_method_name(method))
end
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
test_app = lambda do |env|
[200,
{'Content-Type' => 'text/html',
'Content-Length' => '3'}, ['Yes']]
end
describe test_app, 'RackApp' do
it { should respond_to(:call) }
# This module helps converting to string every object that includes it
module Stringfier
attr_reader :app
def to_str
"Your app http status is: -> #{@app[0]}<-, " + \
"with headers: ->#{@app[1]}<-, " + \
"and body: ->#{@app[2]}<-"
end
end
#Refactor following code using singleton pattern and explain your answer
require 'singleton'
class Logger
include Singleton
LOG_FILE_NAME = 'dev.log'
def initialize