Skip to content

Abstract initialization of your code #6

Description

@clbustos

On many classes, the initialize method is always the same

          def initialize
            super
            set_options(self.class.options) if self.class.options 
            self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
            buildClassifier(self.class.data)
          end

You should create a base module, like RubyMining, with a method that run this procedure
Example:

        module RubyMining
        def init_classifier
            super
            set_options(self.class.options) if self.class.options 
            self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
            buildClassifier(self.class.data)
         end
         end
         class Base < NaiveBayes
         include ::RubyMining
         def initialize
         super
          init_classifier
         end
         end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions