@1337807 (7) [Avatar] Offline
#1
module ApplicationHelper
def title(*parts)
unless parts.empty?
content_for :title do
(parts << "Ticketee"smilie.join(" - "smilie unless parts.empty?
end
end end
end

I think the second parts.empty? check is redundant?

(parts << "Ticketee"smilie.join(" - "smilie unless parts.empty?

Doesn't the previous unless parts.empty? logic prevent that ever from being the case?
belovedofdeath (5) [Avatar] Offline
#2
Re: Chapter 3, Figure 3.24
I'm new to Ruby, buuuuut:

I thought that same thing too, but then I asked my coworker what "<<" meant, and here's his response:

"push this fucking thing into that fucking thing. For adding an element to an array, for example."

(I have colorful coworkers.)

Seeing as it's inside a do-loop, and because I know that arrays generally come with push and pop methods, it looks like it's pushing all of it's guts out into the string "Ticketee" and separating them with " - ". It becomes empty once it reaches the end of the array (parts). So, we need to check for it being empty again. We also don't want to go into the loop if it's not empty already, so it would appear that both are necessary?

Though, you could probably do away with the first empty? check and still have it work maybe?

Unsure of what best practices are here for this kind of a scenario, but maybe that'll help you out since you were thinking that the second one should be taken out. smilie
ryanbigg (423) [Avatar] Offline
#3
Re: Chapter 3, Figure 3.24
I either forgot to reply to this thread or just didn't see it. Sorry for that.

This was pointed out to me again today and I've fixed it up. It'll be out in the second edition of the second edition (so not this release, but the next one).