On Fri, Apr 18, 2008 at 11:06 AM, Rob Kaufman <[EMAIL PROTECTED]> wrote:

> The _ prefix doesn't seem like a winner to me.  _ is valid at the start of
> the method names just as much as variable names, so your relying solely on
> someone being 'in the know'.


I don't use the _ prefix or suffix much, but it does seem legitimately
useful for distinguishing a local variable from a member or class method
with the same name. Especially in an ActiveRecord object when you want to
work with some new value before assigning it to a property of the same name.

class Widget < AR::Base
  # t.integer :rating
  def assign_rating(_rating)
    rating = do_something_with(_rating)
  end
end

That's pretty quick and easy, but I also tend to rely on 'self' or slightly
more descriptive variable names. Like so:

class Widget < AR::Base
  # t.integer :rating
  def assign_rating(new_rating)
    rating = do_something_with(new_rating, self.rating)
  end
end

When in doubt, I go for longer variable and method names over syntactical
minutiae. Contrived example, YMMV, BBQ, etc. ;)

I really appreciate your post.  It is great to talk over these kinds of
> semantic and syntactic 'nitty-gritty' here.


Likewise. Good question. That recent thread on implementation and
benchmarking of obscure methods was good, too. +1 for Ruby nitty-gritty :)

Also, nice cached method tip, Rob. I haven't used the second form much but
just dropped it in to a project of mine.

-- 
Nick Zadrozny * beyondthepath.com

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to