Which Class? Puts it in?
Tags: ruby, tutorial, codenewbie, refactorit
Published: 2020-07-21 16:27:33

I just wrote a CLI (Command Line Interface) [app](https://github.com/kak79/CLI-PROJECT).  I do not say finished, because I'm still refactoring it. I have multiple classes in this [app](https://github.com/kak79/CLI-PROJECT).  The viewpoints on class responsibility vary. Specifically the interface class responsibility versus the methods class. Some say that you could put `puts`, `inputs` and `gets` methods in whichever class you could justify them.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ce13xrnvjy1na5xh18cx.jpg) 
Others say that they need to be in the CLI class so that if I ever change the project to a web project they will all need to be in the same class and not in the methods class for ease of access.

In my case we are dealing with `class CLI` and `class Photographer`.  Most of my `puts`, `inputs` and `gets` are in [`class CLI`](https://github.com/kak79/CLI-PROJECT/blob/master/lib/cli.rb), but having listened closely to everyone, I have decided that I need to do some refactoring of these methods in `class Photographer` in order to move the puts to `class CLI`.  

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cm1b0b7bepvhah66p0l7.jpg)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/nssiaczoh0nui6hx2kma.jpg)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n6jniwqsmfl0q44b02sk.jpg)

First I am going to copy the two methods with the `puts` statements whole and paste them into the `CLI class`.  Then I have to change a few things to make them a part of class `CLI`. 

The first thing I do after moving pic_taker_array to `CLI` is change it from a class method to an instance method by removing the `self.`. I also need to change the way I call it in the `CLI` class from `Photographer.pic_taker_array` to `pic_taker_array`.  Then I put a [pry](https://dev.to/honeybadger/why-pry-is-one-of-the-most-important-tools-a-junior-rubyist-can-learn-2mp7) on the first line of this method so that I can see exactly how I need to modify it.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/32838mjfw9chnpjv0336.jpg)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/g9id3cufkgjpo1e8lqdx.jpg)


I have a method in my `Photographer` class called `self.all` that calls `@@all` so I'm going to try that in my `pry`.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2qizt81i42fjpnhwnkzo.jpg)

I run the program and see that my photographers are no longer displayed properly.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m5kmwz061xq7m393hh84.jpg)

I need to edit the display method so that so that it will accept a photographer into the methods pic_taker, pic_taker_url, and orig_url. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/uasu5y1yhfz3u4imhopi.jpg)

I try running my program again and realize that display is not getting called. This leads me to the line of the `glue` method where `search_pic_taker_array` is supposed to be called but is getting skipped, so I decide to take the contents of `search_pic_taker_array` and move them to `glue`.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tqqc46xkwdxi7j31708q.jpg)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4bj60980gzsjcezpnnjt.jpg)

I run my program and check everything. The photographers display perfectly now! 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ruf3aepz6z11jsfcxtrc.jpg)