Tony
Tony

Reputation: 19151

What does the ruby method "in" do?

It's a bit hard to search for it. This might actually be a Rails method.

Upvotes: 0

Views: 143

Answers (2)

nicholasklick
nicholasklick

Reputation: 1212

"in" is used as an alternative to the array.each do |a| syntax

array = [1,2,3,4]

for a in array
 puts a
end

1
2
3
4

Upvotes: 0

Chuck
Chuck

Reputation: 237060

If you want to know what any method does, just do "ri the_method" from the shell. In this case, "ri in" reveals Date#in. "ri Date.in" gives:

Alias for #since

In turn, "ri Date.since" gives:

Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00) and then adds the specified number of seconds

And yes, it's in ActiveSupport.

Upvotes: 3

Related Questions