Which version of Ruby are you using? The documentation link you provided is for Ruby 2.0. The Dir.exists?
method was not available in 1.8.
You can check your Ruby version from the command line with:
ruby -v
Or from an IRB session, check the value of the RUBY_VERSION
constant.
If you're interested in using newer/multiple Ruby versions on your machine, I recommend looking into RVM or rbenv.