Topic: What do these " -- " characters do?

I am trying to figure out the 'bones' of a restful_authentication routine and find a line as " self.remembrall = encrypt("#{self.salt}--#{self.id}--#{Time.now}") ".
What do these two dashes signify / accomplish?
Thank you,
David

Re: What do these " -- " characters do?

I don't think anything. He's just building a unique string and wanted to use dashes to keep the values separated.

Railscasts - Free Ruby on Rails Screencasts

Re: What do these " -- " characters do?

Ryan, So is the string created something like "salt.value+--+id.value+--+time.value"? What I'm asking is if the "--" are part of the string that's created?

Re: What do these " -- " characters do?

Those dashes are just decorations inside the string. They separate the interpolated strings... which look like #{this}. Basically if you have a string and want to execute some ruby in the middle of it,

"You could do #{your_dynamic_method_here}"

Just make sure to use double quotes or this wont work.

You must also escape any double quotes inside your string.. For example

"<p id=\"some_id\">#{dynamic.name}</p>"

This type of syntax is most commonly used inside helper files.

Last edited by pimpmaster (2007-05-16 11:24:38)

Re: What do these " -- " characters do?

Thanks, Pimpmaster. I guess I'll try it again...are the "--" integrated into the resulting string?
David

Re: What do these " -- " characters do?

Indeed they are .. the author could have just as easily written

self.rememberall = encrypt("This is the salt:#{self.salt} This is the id:#{self.id} This is the time:#{Time.now}") "

But instead he used a couple of dashes

In PHP it would look like this:

$salt + "--"  + $id + "--"  + $time

Last edited by pimpmaster (2007-05-16 13:17:59)

Re: What do these " -- " characters do?

pimpmaster wrote:

In PHP it would look like this:

$salt + "--"  + $id + "--"  + $time

Or like this wink

$salt . "--" . $id . "--" . $time

Or even closer to what the original post was like...
"{$salt}--{$id}--{$time}"

Not that the curly braces are really necessary.

To OP...

The -- are just dashes used to make the hash/encryption even MORE unique than it would have been without the dashes, they are encrypted along with the rest of the string.

Last edited by clayton (2007-05-17 02:45:49)

Re: What do these " -- " characters do?

Hah! So the truth comes out... you are a recovering PHP junkie tongue

Re: What do these " -- " characters do?

pimpmaster wrote:

Hah! So the truth comes out... you are a recovering PHP junkie tongue

I'm a current PHP junkie, in the sense that I have to use it to survive and am trying to quit.  It's like those old anti-drug commercials "Nobody ever says they want to be a PHP coder when they grow up".