I’m new to Ruby… do you need ='s signs for assigment?
On this page:
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 “[email protected]”
subject “New account information”
body :account => recipient
end
end
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 “[email protected]”
subject “New account information”
body :account => recipient
end
end
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 “[email protected]”
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(“[email protected]”)
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.
Some people don’t like parentheses. Personally I use them abundantly
(even though I’ve never studied Lisp). Most of the time parentheses make
things clearer.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.