On 1/30/07, cmdjackryan / googlemail.com <cmdjackryan / googlemail.com> wrote:
> As I'm a beginner in Ruby, and just (re)started working on real code,
> instead of working through various tutorials, I'm asking myself: Is that
> the Ruby way?
>
> Snippet:
>
> unless File.exists?('data/finance.db') == true
>    setup = Database.new
>    setup.new_database
>    else
>      puts 'Database already exists!'
> end
>

class Database
  def self.create file = 'data/finance.db'
    if File.exist?(file)
      puts 'Database already exists!'
    else
      new file
    end
end

Database.create

>
> The code is tested and working as expected (Database is my own class,
> which creates the database in the first place), and I don't think it
> could be (much) shorter.

This is just to show that Database itself should take responsibility
over creation/checking. It's just a small example but should give you
an idea.
Tell, don't do :)

^ manveru
>
> -Phill