ruby - Is there a way to avoid definition of a method with a certain name? -


is there way avoid (raise error when attempted) definition of method name, example foo#bar? (a usecase when foo#bar defined, , want avoid method being overridden, irrelevant question.) assuming like:

class foo   prohibit_definition :bar end  ... # later in code  class foo   def bar     ...   end end # => error: `foo#bar' cannot defined 

maybe can catch callback in method_added() of module class , check method name , delete added method if not meet criteria. can raise error.

not want close enough think.

class class   def method_added(method_name)     if method_name == :bar         remove_method :bar         puts "#{method_name} cannot added #{self}"   end end 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -