Created
January 15, 2015 20:41
-
-
Save jamesdabbs/2762dd3a9aaaf9256eae to your computer and use it in GitHub Desktop.
Production Ready™
This file contains 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 'pry' | |
require 'binding_of_caller' | |
class Symbol | |
def and_then snd=nil | |
fst = self.to_s | |
binding.of_caller(1).eval %{ | |
define_method :#{fst}_and_then_#{snd} do | |
send :#{fst}_without_#{snd} | |
send :#{snd} | |
end | |
alias_method :#{fst}_without_#{snd}, :#{fst} | |
alias_method :#{fst}, :#{fst}_and_then_#{snd} | |
} | |
end | |
end | |
class Thing | |
def get_happy | |
puts "Woo!" | |
end | |
def think_about_it | |
puts "Hrm ..." | |
sleep 1 | |
end.and_then :get_happy | |
end | |
Thing.new.think_about_it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment