Skip to content

Instantly share code, notes, and snippets.

@mduvall
Created November 30, 2011 22:40
Show Gist options
  • Save mduvall/1411508 to your computer and use it in GitHub Desktop.
Save mduvall/1411508 to your computer and use it in GitHub Desktop.
andand call chain, or a crude attempt to
require 'rubygems'
require 'sourcify'
require 'andand'
def with_andand(&blk)
methods = blk.to_source.split("{")[1].split("}")[0].split(".").each { |w| w.strip! }
main_object = methods.first
methods = methods.slice(1,methods.length)
methods.each do |meth|
main_object = eval("#{main_object}.andand.#{meth}")
return 0 if !main_object
end
main_object
end
class Hello
def self.hello
Object.new
end
end
class Goodbye
def self.goodbye
nil
end
end
with_andand { p Hello.hello }
with_andand { p Goodbye.goodbye }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment