SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby on Rails Main?

    Hi all,

    I have received great feed back not too long ago and was wondering if someone could answer a question I have. I have a book I ordered Simple Rails 2.0 and I can not wait to get it. It has great reviews. I was looking through the code of the data base programmed in Ruby on Rails. I was studying Ruby and noticed that there is a main section to start the program from a tutorial website. This makes since for me coming from a C++, C# background in which every program has a main method that starts the program.

    Here is the example I was looking at:

    begin
    # ->code inserted for this block
    end

    rescue TruncatedDataError
    # ->code inserted for this block
    end

    ensure
    # ->code inserted for this block
    end

    I was looking at our code for our database website that is programmed in Ruby on Rails but none of the .rb files has this main block in it. What else could be used to start the program or do you guys believe files are missing? I believe files are missing because one script file when open has nothing but errors as if a need script that it pulls classes from may have these variables.

  2. #2
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Location
    Wherever danger lies...
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In contrast to C++ where an entry point main() must be defined, in Ruby, the entry point is the first line of the program passed on the command-line to the Ruby interpreter. For example, if you run "ruby myfile.rb" then the code will be executed starting at the very first line of myfile.rb.

    The begin-rescue-ensure blocks that you point to are portions of code in which exceptions (errors) can be explicitly handled -- try-catch-finally from C++.

    -> Exceptions, Catch, and Throw

    In Rails, project files typically have no code with visible effects like writing to stdout. Most either set configuration options for Rails, or define classes for serving the web site. In fact, the entry point is the web server (script/server), which calls upon the Rails project code only for handling web requests.
    There are some things you shouldn't try to code at home.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •