rsl (owner)

Revisions

gist: 199972 Download_button fork
public
Public Clone URL: git://gist.github.com/199972.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module TryChain
  def try_chain(*method_list)
    target = self
    method_list.each do |method|
      target = target.send(method)
    end
    target
  rescue NoMethodError
    nil
  end
end
 
module NilTryChain
  def try_chain(*method_list)
    nil
  end
end
 
ActiveRecord::Base.__send__ :include, TryChain
NilClass.__send__ :include, NilTryChain