# Missing parantheses maybe?

**URL:** <https://www.ruby-forum.com/t/missing-parantheses-maybe/64337>\
**Category:** Ruby\
**Created:** [June 24, 2006, 1:13pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337 "2006-06-24T13:13:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 24, 2006, 1:13pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337/1 "2006-06-24T13:13:25Z")

</div>

Trying to do some fancy formatting and getting an error message.  
Since I know .center is a method the error message can’t be the  
ultimate truth. Anyone ?

```
                      Table of Contents <------This is corect

```

toc.rb:8: undefined method `center’ for [2]:Array (NoMethodError)

> Exit code: 1

toc = [‘Table of Contents’, ‘Chapter 1’, ‘Getting Started’,  
‘page 1’, ‘Chapter 2’, ‘Numbers’, ‘page 9’,  
‘Chapter 3’, ‘Letter’, ‘page 13’]

```
    line_width = 70

    puts( toc[0].center(line_width))
    puts( toc[1].ljust(line_width/2) +

```

[2].center(line\_width) +[3].rjust(line\_width/2))  
puts( toc[4][5][6])  
puts( toc[7][8][9])

Tia  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 24, 2006, 1:16pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337/2 "2006-06-24T13:16:34Z")

</div>

2006/6/24, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Trying to do some fancy formatting and getting an error message.  
> Since I know .center is a method the error message can’t be the  
> ultimate truth. Anyone ?

I’m not sure what you’re implying here, but as the error message  
indicates Array#center is nonexistent. You probably want  
String#center as in

irb(main):002:0\> “fff”.center 10  
=\> " fff "

You also probably missed a toc there:

> ```
> puts( toc[0].center(line_width))
> puts( toc[1].ljust(line_width/2) +
> 
> ```
> 
> [2].center(line\_width) +[3].rjust(line\_width/2))  
> ^^^

“toc” missing here.

> ```
> puts( toc[4][5][6])
> puts( toc[7][8][9])
> 
> ```

Cheers

robert

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 24, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337/3 "2006-06-24T13:22:43Z")

</div>

Hopefully it was a beginners mistake and not a pattern of my own logic  
🙂  
Thanks Robert!

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 24, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337/4 "2006-06-24T13:38:28Z")

</div>

.rjust dosn’t seem to be working correctly, no error, but it’s not  
right justifying either.

my output for the .rjust looks like this:  
Chapter 1 Getting Started  
page 1  
Chapter 2 Numbers  
page 9  
Chapter 3 Letter  
page 13

here is the first line (Chapter 1…)

puts( toc[1].ljust(line\_width) + toc[2].ljust(line\_width)

- toc[3].rjust(line\_width))

I hand tweaked teh .rjust parameter with hard numbers .rjust(20)

```
    .rjust(25), etc and that helped but I thought .rjust would

```

make sure the last letters of the strings would all line up.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [June 25, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/missing-parantheses-maybe/64337/5 "2006-06-25T20:53:20Z")

</div>

2006/6/24, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> here is the first line (Chapter 1…)
> 
> puts( toc[1].ljust(line\_width) + toc[2].ljust(line\_width)
> 
> - toc[3].rjust(line\_width))
> 
> I hand tweaked teh .rjust parameter with hard numbers .rjust(20)
> 
> ```
> .rjust(25), etc and that helped but I thought .rjust would
> 
> ```
> 
> make sure the last letters of the strings would all line up.

For this scenario sprintf / printf are probably better suited.

Kind regards

robert
