Skip to main content

Vincent Tsao's Library tagged ruby   View Popular

17 Sep 09

Active Record Query Interface

  • Behind the scenes find_each fetches rows in batches of 1000 and yields them one by one. The size of the underlying batches is configurable via the :batch_size option.


    To fetch User records in batch size of 5000:

  • User.find_each(:batch_size => 5000) do |user|
    NewsLetter.weekly_deliver(user)
    end
  • 1 more annotations...

Active Record Validations and Callbacks

  • 17 Observers


    Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn’t directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a User model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn’t directly related to your model, you may want to consider creating an observer instead.

Eli Bendersky’s website » Blog Archive » Understanding Ruby blocks, Procs and methods

  • Procs play the role of functions in Ruby. It is more accurate to call them function objects, since like everything in Ruby they are objects. Such objects have a name in the folklore - functors. A functor is defined as an object to be invoked or called as if it were an ordinary function, usually with the same syntax, which is exactly what a Proc is.
  • Actually, there are two slight differences between lambda and Proc.new. First, argument checking. The Ruby documentation for lambda states: Equivalent to Proc.new, except the resulting Proc objects check the number of parameters passed when called.. Here is an example to demonstrate this:
  • 6 more annotations...
1 - 20 of 198 Next › Last »
Showing 20 items per page

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo