liliverson45 / Hello_World

My Hello World Ruby Training
0 stars 0 forks source link

How can we make this more re-usable? #4

Closed anthonycarlos closed 7 years ago

anthonycarlos commented 8 years ago

John:

It looks like you're comfortable using the gets command to force the user into entering a string of text. That's great, but think about trying to check for palindromes with different input sources. Sure, a user could type in words. But what if you wanted to check in the middle of your program whether a word was a palindrome or not? What if you wanted to check a whole bunch of words from a text file? Can you think of a way to pull your code into something that can separate the checking from the input behavior? Here's a hint: define a method so I can call it like this:

JohnsStringUtil.palindrome?("lol")

=> true

TODO: Create a class called JohnsStringUtil. Define a class method called palindrome? that takes a parameter and returns true if the parameter is a palindrome or false if it is not a palindrome.

During your research about classes and methods, you may run into discussions about class methods and instance methods. That opens up discussions about objects. Suffice to say that we're not going to create instances of your utility class just yet, so class methods will work just fine.

Let me know if you have questions.

Good luck,

-Anthony