Topic: Make new function with a ?

Hello! How do I make a new function that uses a ? in it, like .nil? This is what I have right now:

  def exists? (teacher)
    if teacher.nil?
      return FALSE
    else
      return TRUE
    end
  end

However, when I use it, for example: Teacher.find_by_id(1).exists? then I get an error that it's missing arguments. How do I do this?

Thanks,
Michael Boutros

Re: Make new function with a ?

Your "exists?" method accepts an argument but you aren't passing it one. I think what you want is already in Rails:

Teacher.exists?(1)

A method with a question mark is just like any other method. Ruby doesn't know a difference.

Railscasts - Free Ruby on Rails Screencasts