Is there an equivalent to the prepend method in ruby ββ1.9.3?
I need to use a method prepend
introduced in ruby ββ2.0 in ruby ββ1.9.3 where this method is not supported. Is there an equivalent method in ruby ββ1.9.3?
UPDATE
I need this to work with ruby ββ1.9.3
module ActiveAdmin::Views::Pages::BaseExtension
def add_classes_to_body
super
@body.set_attribute "ng-app", "MyApp" #I need to add this line
end
end
class ActiveAdmin::Views::Pages::Base
prepend ActiveAdmin::Views::Pages::BaseExtension
end
+3
source to share
2 answers
prepend
changes the underlying Ruby object model, specifically the way messages are sent, in pure Ruby there is no way to do this, so there is no way to back up functionality prepend
.
In the good old days before, prepend
we used this instead:
class ActiveAdmin::Views::Pages::Base
orig = instance_method(:add_classes_to_body)
define_method(:add_classes_to_body) do
orig.bind(self).()
@body.set_attribute "ng-app", "MyApp"
end
end
0
source to share
I could make it work using alias_method
class ActiveAdmin::Views::Pages::Base
alias_method :old_add_classes_to_body, :add_classes_to_body
def add_classes_to_body
old_add_classes_to_body
@body.set_attribute "ng-app", "MyApp"
end
end
0
source to share