class Object

Try taken from github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/object/try.rb

Public Instance Methods

local_methods(obj = self) click to toggle source

Return a list of methods defined locally for a particular object. Useful for seeing what it does whilst losing all the guff that's implemented by its parents (eg Object).

# File lib/elected/core_ext.rb, line 7
def local_methods(obj = self)
  (obj.methods - obj.class.superclass.instance_methods).sort
end
try(*a, &b) click to toggle source
# File lib/elected/core_ext.rb, line 11
def try(*a, &b)
  try!(*a, &b) if a.empty? || respond_to?(a.first)
end
try!(*a) { |self| ... } click to toggle source
# File lib/elected/core_ext.rb, line 15
def try!(*a, &b)
  if a.empty? && block_given?
    if b.arity.zero?
      instance_eval(&b)
    else
      yield self
    end
  else
    public_send(*a, &b)
  end
end