[ ruby ] yield and block

class WhateverClass
def whateverMethod()
status = 1
description = "whatever"
...
yield status, description
end
end

whateverObject = WhateverClass.new
whateverObject.whateverMethod() do |status, description|
# do anything with status and description
...
end

Return from yield

class WhateverClass
  def whateverMethod()
    status = 1
    description = "whatever"
    ...
    yield status, description ## return will be the last line
  end
end

whateverObject = WhateverClass.new
whateverReturn = whateverObject.whateverMethod() do |status, description|
  # do anything with status and description
  ...
"whateverReturn naja" ## return will be the last line
end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s