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
Post a Comment