01 Apr 2014, 02:40

Eryk Koziol (2 posts)

Hi all,

I’m hoping someone can help me with a query I have about the methods ‘center’, ‘ljust’ and ‘rjust’, covered on page 31.

Why is there a parenthesis after the puts method? for example, there’s a line which reads as: ‘puts( ‘Old Mother Hubbard’.center(line_width))’

When I did the following, I got the same output in my terminal: ‘puts ‘Old Mother Hubbard’.center(line_width)’

I thought it may be needed for the aesthetic spacing but noticed it was also used on the justify examples.

If anyone could shed any light on this that would be great, probably something obvious I’m missing.

Cheers, Eryk.

02 Apr 2014, 00:44

Chris Pine (58 posts)

It’s only there to make sure that this code works in as many different versions of Ruby as possible. Some versions have slightly different rules for when you need parentheses.

02 Apr 2014, 00:58

Eryk Koziol (2 posts)

Thanks Chris.

  You must be logged in to comment