Skip to content

Instantly share code, notes, and snippets.

View mikhailbortnyk's full-sized avatar

Mikhail Bortnyk mikhailbortnyk

View GitHub Profile
@mikhailbortnyk
mikhailbortnyk / chainmethods.rb
Last active December 15, 2015 07:09
ChainMethod extension for Object
class ChainMethod
def initialize(method_name, params = [], callbacks = {})
@method_name = method_name
@params = params
@callbacks = callbacks
end
def call(base_object)
# preparation work
result = base_object
@mikhailbortnyk
mikhailbortnyk / secret_token.rb
Created January 24, 2013 16:04
config/initializers/secret_token.rb
require 'clickworker-secure-config/helper'; include Clickworker::SecureConfig::Helper
# Be sure to restart your server when you modify this file.
# Your secret key for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
ClickworkerProfile::Application.config.secret_token = get_secret_by_key('profile.secret_token') || 'd69b09956e0ccef4351f239dcbbc3265'
--- ~ » irb
1.9.3p286 :001 > class A
1.9.3p286 :002?> def to_modify
1.9.3p286 :003?> "Not modified"
1.9.3p286 :004?> end
1.9.3p286 :005?> end
=> nil
1.9.3p286 :006 > def redefine_method(klass, &block)
1.9.3p286 :007?> if klass.new.respond_to?(:to_modify)
1.9.3p286 :008?> klass.send(:define_method, :to_modify, &block)