Skip to content

Instantly share code, notes, and snippets.

@jamesdabbs
Created January 15, 2015 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesdabbs/2762dd3a9aaaf9256eae to your computer and use it in GitHub Desktop.
Save jamesdabbs/2762dd3a9aaaf9256eae to your computer and use it in GitHub Desktop.
Production Ready™
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