# FAQ: Methods, Blocks, & Sorting - How Blocks Differ from Methods

This community-built FAQ covers the “How Blocks Differ from Methods” exercise from the lesson “Methods, Blocks, & Sorting”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise How Blocks Differ from Methods

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

In the following line;

``````puts "#{string[0].upcase}#{string[1..-1]}"
``````

I don’t understand why ‘…-1’ works as it does. Can anyone explain this bit?

7 Likes
2 Likes

Hi, an experiment to this exercise got me baffled - there are numbers now!
can s.b. explain?

same for me, i don’t quite understand what it is referring too … is there anyone to enlight me please

Using negative index numbers starts from the end of the array, rather than the beginning. As there’s no negative Zero, Array[-1] will return the final element of the array.

That line is saying, 'return the first element of the string ( string[0] ) as an upper case string, and then return every other element from the second up to and including the final element ( string[1…-1] )

15 Likes

very nice all clear now
thanks a lot !!

I don’t understand why the first method has to iterate over every letter in the string. Wouldn’t it be simpler to just do this?:

# method that capitalizes a word

def capitalize(string)
puts “#{string.capitalize}”
end

4 Likes

Can anyone explain to me why this example created a method to capitalize and didn’t just do

puts “#{string.capitalize!}” - it gives the exact same output as puts "#{string[0].upcase}#{string[1…-1]}

Thanks

1 Like

This really helped the most. I had no idea -1 was the end of an array.

So [0…-1] just means from the first to the last in the array?