lundi 21 septembre 2015

How to refactor the below code in such a way that if I made changes in display_home_page method I need not to make changes in the process method

    def display_home_page
      print "  1 My Timeline\n  2 tweet\n  3 Other's  Timeline\n  4 Retweet\n  5 Follow\n  6 My Wall\n  7 logout\nEnter your choice : "
    end

    def process(choice)
      if choice == "1"
        my_timeline
      elsif choice == "2"
        tweet
      elsif choice == "3"
        others_timeline
      elsif choice == "4"
        re_tweet
      elsif choice == "5"
        follow
      elsif choice == "6"
        my_wall
      else
        error_message
      end
    end

above two methods: 1 display_home_page : To display on the console 2 process : for calling the method based on user input on choice variable.

Aucun commentaire:

Enregistrer un commentaire