ruby - Module method access restriction -


i have class c inherits class a , includes module b. a has method baz.

class   def baz; 5 end end  module b   def foobaz; baz end end  class c <   include b   def barbaz; baz end end 

i want disallow b instance (indirectly) calling baz, allow c instance call baz.

b.new.foobaz # => error c.new.foobaz # => no error c.new.barbaz # => no error 

how this?

maybe wanted ?

class   def baz; 5 end end  module b   module_function   def foobaz     self.respond_to(:baz) ? baz : "no baz defined :("   end end  class c <   include b   def barbaz; baz end end  b.foobaz # => "no baz defined :(" c.new.foobaz # => 5 c.new.barbaz # => 5 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -