ruby trick question

Okay, back to nuts and bolts programming.

Can anyone explain exactly what’s going on when ruby does, like “20.minutes.ago”. I mean, #minutes must be a method on numeric values, right? So why can’t I find it included in the rdoc for Integer or Numeric? And then #minutes  returns some kind of object that has an #ago method. So, um, what kind? I don’t get it. I like to understand what’s going on.

This entry was posted in programming. Bookmark the permalink.

One Response to ruby trick question

  1. mjgiarlo says:

    I know we already talked about this on #code4lib, but I figured I’d post the answer here for posterity.

    http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html

    #minutes and #ago are both provided by ActiveSupport. The documentation above isn’t terribly helpful, but the source code gives hints.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s