Ruby doesn't need equal's signs for assigment?

P

Peter Alvin

I'm new to Ruby... do you need ='s signs for assigment?

On this page:

http://api.rubyonrails.org/classes/ActionMailer/Base.html

I see this example over and over.. where are the equal's signs???

class Notifier < ActionMailer::Base
def signup_notification(recipient)
recipients recipient.email_address_with_name
from "(e-mail address removed)"
subject "New account information"
body :account => recipient
end
end

TIA, Pet
 
R

Robert Klemme

2008/9/2 Peter Alvin said:
I'm new to Ruby... do you need ='s signs for assigment?

On this page:

http://api.rubyonrails.org/classes/ActionMailer/Base.html

I see this example over and over.. where are the equal's signs???

I can confirm that there are no equal signs in the code. ;-)
class Notifier < ActionMailer::Base
def signup_notification(recipient)
recipients recipient.email_address_with_name
from "(e-mail address removed)"
subject "New account information"
body :account => recipient
end
end

These are all method invocations.

Kind regards

robert
 
J

James Coglan

[Note: parts of this message were removed to make it a legal post.]
I see this example over and over.. where are the equal's signs???

class Notifier < ActionMailer::Base
def signup_notification(recipient)
recipients recipient.email_address_with_name
from "(e-mail address removed)"
subject "New account information"
body :account => recipient
end
end



You need = signs for assignment. In ActionMailer those are implemented as
methods to make the syntax a bit cleaner. A more verbose way to write the
above using full method call syntax:

class Notifier < ActionMailer::Base
def signup_notification(recipient)
self.recipients(recipient.email_address_with_name)
self.from("(e-mail address removed)")
self.subject("New account information")
self.body:)account => recipient)
end
end

This is why Ruby is known for being a good language for writing DSLs
(domain-specific languages, ie mini-languages for describing specific
problems), since its method call syntax does not require 'self' and lots of
parentheses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top