I have this script from “Why’s poignant guide to Ruby”:
http://pastie.org/1043938
And, have the following questions:
1- def join( sep = $, format = “%s” )
What is:
$,
“%s”
?
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” )
Thanks.
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
Thanks,
Allan D.
Member of NetBeans Dream Team
http://wiki.netbeans.org/NetBeansDreamTeam
Lead Developer, nbPython
http://wiki.netbeans.org/Python
http://codesnakes.blogspot.com (my blog)
http://www.linkedin.com/in/javaalley
On Wed, Jul 14, 2010 at 8:09 AM, Abder-Rahman A. <