[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Peter Alvin

9/2/2008 11:05:00 AM

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

On this page:

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

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 "system@example.com"
subject "New account information"
body :account => recipient
end
end

TIA, Pet
--
Posted via http://www.ruby-....

4 Answers

Robert Klemme

9/2/2008 11:13:00 AM

0

2008/9/2 Peter Alvin <form@awebabove.com>:
> I'm new to Ruby... do you need ='s signs for assigment?
>
> On this page:
>
> http://api.rubyonrails.org/classes/ActionMailer...
>
> 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 "system@example.com"
> subject "New account information"
> body :account => recipient
> end
> end

These are all method invocations.

Kind regards

robert


--
use.inject do |as, often| as.you_can - without end

James Coglan

9/2/2008 11:14:00 AM

0

[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 "system@example.com"
> 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("system@example.com")
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.

Peter Alvin

9/2/2008 11:36:00 AM

0

> These are all method invocations.

OHHHHHHH!!! DUH! Thanks so much!
--
Posted via http://www.ruby-....

Dave Bass

9/3/2008 10:38:00 AM

0

Peter Alvin wrote:
>> These are all method invocations.
>
> OHHHHHHH!!! DUH! Thanks so much!

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.
--
Posted via http://www.ruby-....