...

/

Writing a new Method

Writing a new Method

This lesson demonstrates the steps of writing new methods in Ruby.

As programmers, we like to split up our tasks and do one thing after another. This allows us to focus on one small task, and once we’ve solved it, we move on to the next one.

When you need to add some new functionality to your program you’ll often find yourself thinking “I should add a method for this”: methods add behavior.

Now, the first thing you should ask yourself is: “What is it that this method should do?” The answer to this gives you a hint for a good method name.

Example

Let’s say you ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy