Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created May 7, 2009 19:31
Show Gist options
  • Select an option

  • Save jaredatron/108300 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/108300 to your computer and use it in GitHub Desktop.
class Object
define_method :returning_self do
ReturningSelf.new(self)
end
class ReturningSelf
private *instance_methods.select { |m| m !~ /(^__|^\W|^binding$)/ }
def initialize(subject)
@subject = subject
end
def method_missing(sym, *args, &blk)
@subject.send(sym,*args,&blk)
@subject
end
end
end
# [1,2].compact!
# => nil
# [1,2].returning_self.compact!
# => [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment