Call method only if it exists

If you are not satisfied with the standard ruby syntax for that, you are free to:

class Object
  def try_outside_rails(meth, *args, &cb)
    self.send(meth.to_sym, *args, &cb) if self.respond_to?(meth.to_sym)
  end
end

Now:

resource.try_outside_rails(:phone_number)

will behave as you wanted.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)