This script is a bit confusing!

I have this script from “Why’s poignant guide to Ruby”:

And, have the following questions:

1- def join( sep = $, format = “%s” )

What is:


2- How can I call a method on “end”? What is the purpose of doing it
like that?

end.join( sep )

3- What is meant by this statement?

rooms.join(", ", “%d bed” )


class ArrayMine < Array def join( sep = $, format = “%s” )

%s is a c style format string meaning a string will go here

$, is a global accessor and in my system case it was nill

collect do  |item|
  sprintf( format, item )    end.join( sep ) # what string is

returned from the block do the join on it endend

rooms = ArrayMine[3, 4, 5]
print “We have " + rooms.join(”, “, “%d bed” ) + " rooms available.”

%d is another c format code that says a digit will be go here

Hope this helps


Allan D.
Member of NetBeans Dream Team
Lead Developer, nbPython (my blog)

On Wed, Jul 14, 2010 at 8:09 AM, Abder-Rahman A. <

Thanks a lot.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs