0
class Employee
  attr_accessor :id, :salary, :birthday... # about 10 more attribures

  def qualify_for_raise?  ..... end 

  def qualify_for_promotion? ..... end 

  # 10 more instance method
end

class Review
  def review(employee_array)
    employee_array.map do |employee|
      if employee.qualify_for_raise?
        # ...
      end
      if employee.qualify_for_promotion?
        # ...
      end
      # ... 
    end
  end
end

Since I will create 50,000 Employee objects, would it be better to take all instance methods out of Employee class as each Employee object will have its own copy of instance methods? If that's true, I have design my classes like below, I much prefer declaring methods to operate on Employee data inside Employee class itself. Is there a way to find out size of Employee object with/without instance methods?

class Employee
  att_accessor :id, :salary, :birthday... # about 10 more attribures
end

class Review
  def review(employee_array)
    employee_array.map do |employee|
      if is_qualify_for_raise(employee)
        # ...
       end
       if is_qualify_for_promotion(employee)
         # ...
       end
       # ... 
     end
   end

   def is_qualify_for_raise(employee)  ..... end 
   def is_qualify_for_promotion(employee) ..... end 
   # 10 more methods
end
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
user612308
  • 1,813
  • 5
  • 23
  • 22

1 Answers1

3

An instance of an object doesn't contain copies of its instance methods, therefore the number of instance methods an object has does not affect performance.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214