简体   繁体   中英

What does the ruby method “in” do?

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

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.

"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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM