Featured post
ruby - Protected and private methods in Rails -
method visibility in ruby (public, protected, , private methods) has been explained in places this blog post. in ruby on rails seems different in regular ruby application because of way framework set up. so, in rails models, controllers, helpers, tests, etc., when is/isn't appropriate use protected or private methods?
edit: answers far. understand concept of protected , private in ruby, i'm looking more explanation of typical way types of visibility used within context of various pieces of rails app (models, controllers, helpers, tests). example, public controller methods action methods, protected methods in application controller used "helper methods" need accessed multiple controllers, etc.
for models, idea public methods public interface of class. public methods intended used other objects, while protected/private methods hidden outside.
this same practice in other object-oriented languages.
for controllers and tests, please. both controller and test classes instantiated , called framework (yes, know can theoretically controller view, if that, strange anyway). since no 1 ever create things directly, there's nothing "protect" against.
addendum/correction: controllers, should mark "helper" methods protected private, , actions should public. framework never route incoming http calls actions/methods not public, helper methods should protected in way.
for helpers make no difference if method protected or private, since called "directly".
you can mark stuff protected in cases if makes things easier understand, of course.
- Get link
- X
- Other Apps
Comments
Post a Comment