Hi, I''ve noticed that some of the commits to rails edge lately are using a style where instance variables of a class start with a leading underscore. Like in this commit: http://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414016fc56f I see this variable: @_env I''m guessing it''s to avoid naming conflicts when the module is included in a class? I don''t recall seeing this style in other Ruby libraries (it harkens back to my C++ days), so I''m just wondering if there''s a particular purpose behind it; and whether people who look to contribute code should be adopting this style, and in what situations. Thanks, Jeff -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
We use @_ivars in cases where an instance variable is to be used internally in a module that will be mixed into a user''s class or a class that will be inherited by a user''s class. For instance, we use @_ivars in ActionController::Base and modules mixed into ActionController::Base. Yehuda Katz Developer | Engine Yard (ph) 718.877.1325 On Mon, Jan 11, 2010 at 9:46 PM, Jeff <cohen.jeff@gmail.com> wrote:> Hi, > > I''ve noticed that some of the commits to rails edge lately are using a > style where instance variables of a class start with a leading > underscore. > > Like in this commit: > http://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414016fc56f > > I see this variable: > > @_env > > I''m guessing it''s to avoid naming conflicts when the module is > included in a class? I don''t recall seeing this style in other Ruby > libraries (it harkens back to my C++ days), so I''m just wondering if > there''s a particular purpose behind it; and whether people who look to > contribute code should be adopting this style, and in what situations. > > Thanks, > Jeff > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On Jan 12, 12:12 am, Yehuda Katz <wyc...@gmail.com> wrote:> We use @_ivars in cases where an instance variable is to be used internally > in a module that will be mixed into a user''s class or a class that will be > inherited by a user''s class. > > For instance, we use @_ivars in ActionController::Base and modules mixed > into ActionController::Base.Thanks for the explanation, Yehuda. Sounds logical. Jeff> Yehuda Katz > Developer | Engine Yard > (ph) 718.877.1325 > > > > On Mon, Jan 11, 2010 at 9:46 PM, Jeff <cohen.j...@gmail.com> wrote: > > Hi, > > > I''ve noticed that some of the commits to rails edge lately are using a > > style where instance variables of a class start with a leading > > underscore. > > > Like in this commit: > >http://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414... > > > I see this variable: > > > @_env > > > I''m guessing it''s to avoid naming conflicts when the module is > > included in a class? I don''t recall seeing this style in other Ruby > > libraries (it harkens back to my C++ days), so I''m just wondering if > > there''s a particular purpose behind it; and whether people who look to > > contribute code should be adopting this style, and in what situations. > > > Thanks, > > Jeff > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to > > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-core?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
2010/1/12 Jeff <cohen.jeff@gmail.com>> On Jan 12, 12:12 am, Yehuda Katz <wyc...@gmail.com> wrote: > > We use @_ivars in cases where an instance variable is to be used > internally > > in a module that will be mixed into a user''s class or a class that will > be > > inherited by a user''s class. > > > > For instance, we use @_ivars in ActionController::Base and modules mixed > > into ActionController::Base. > > Thanks for the explanation, Yehuda. Sounds logical. > > Jeff >FYI, other projects like Rack, Clearance also use the same coding style. It is good to see community following one set of guidelines. It just lowers the barrier to entry for a new developer from a different community and keeps the open source code kind of organised. Anuj> > > Yehuda Katz > > Developer | Engine Yard > > (ph) 718.877.1325 > > > > > > > > On Mon, Jan 11, 2010 at 9:46 PM, Jeff <cohen.j...@gmail.com> wrote: > > > Hi, > > > > > I''ve noticed that some of the commits to rails edge lately are using a > > > style where instance variables of a class start with a leading > > > underscore. > > > > > Like in this commit: > > >http://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414. > .. > > > > > I see this variable: > > > > > @_env > > > > > I''m guessing it''s to avoid naming conflicts when the module is > > > included in a class? I don''t recall seeing this style in other Ruby > > > libraries (it harkens back to my C++ days), so I''m just wondering if > > > there''s a particular purpose behind it; and whether people who look to > > > contribute code should be adopting this style, and in what situations. > > > > > Thanks, > > > Jeff > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Core" group. > > > To post to this group, send email to rubyonrails-core@googlegroups.com > . > > > To unsubscribe from this group, send email to > > > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com><rubyonrails-core%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-core?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com<rubyonrails-core%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > > >-- Anuj DUTTA -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
On Mon, Jan 11, 2010 at 11:46 PM, Jeff <cohen.jeff@gmail.com> wrote:> Hi, > > I''ve noticed that some of the commits to rails edge lately are using a > style where instance variables of a class start with a leading > underscore. > > Like in this commit: http://github.com/rails/rails/commit/8cb594a2e1808cd7d93f3593afed0414016fc56f > > I see this variable: > > @_envThis specific example shouldn''t be using the "private ivar" naming style since the Rails module is not an inheritable class. -- Joshua Peek -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.