-1

Basically I am using some engines whose model class uses some gems like acts_as_x. To override the model I use class_eval but I don't need acts_as_x functionalities because it makes heavy calculations that I don't need.

Is there anyway to disable this function?

Thanks,

Updated:

# origin model
class Model < ActiveRecord::Base
 acts_as_x
end

# overriding model
Model.class_eval do 
  acts_as_y
  # it musts remove acts_as_x
end
Moh
  • 249
  • 3
  • 15
  • how does simply calling `acts_as_x` do calculations, it should only define methods.. also what gem is this, or is this something you wrote ? – Mohammad AbuShady Dec 28 '15 at 22:18

2 Answers2

0

If you want not to use something. Don't require it. Or remove_method, http://ruby-doc.org/core-2.3.0/Module.html#method-i-remove_method.

Auli
  • 74
  • 7
  • remove_method didn't work, it says method `acts_as_x' not defined in Model – Moh Dec 28 '15 at 13:25
  • Because it's method missing. So you can't removed it. http://ruby-doc.org/core-2.3.0/BasicObject.html#method-i-method_missing – Auli Dec 28 '15 at 14:08
0
class Roman
  def roman_to_int(str)
    # ...
  end
  def method_missing(methId)
    str = methId.id2name
    roman_to_int(str)
  end
end
r = Roman.new
r.iv      #=> 4
r.xxiii   #=> 23
r.mm      #=> 2000

In ruby doc, When instance of r can't found method. It will be call method_missing and input name. To handle your method and then specifies method to do. If you use ActiveRecord, find_by_xxx is method_missing.

Auli
  • 74
  • 7