Topic: Help with ruby syntax from rails guides

I cannot understand what the code of this function does, could anyone help me with it?

The obscure parts are:
@app||= begin...end (does it mean that if @app does not exist the block is run?)
app ,options = rack::builder... line (whith the comma, so what is it? A couple? I cannot understand the sense...)

this is the code

def app
  @app ||= begin
    if !::File.exist? options[:config]
      abort "configuration #{options[:config]} not found"
    app, options = Rack::Builder.parse_file(self.options[:config], opt_parser)
    self.options.merge! options

Thank you in advance

Re: Help with ruby syntax from rails guides

You are correct in your first assumption it says if @app is nil,  set it to whatever is returned in the block delimited with begin, end

the comma works like this:

vara, varb = "testa", "testb"

If you look at the source for Rack:Builder.parse_file,  you'll see as the last line:

return app, options

So it's returning two values

Last edited by BradHodges (2012-03-31 16:46:38)

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Help with ruby syntax from rails guides

Thank you! You were very clear