开发者

What does the ruby method "in" do?

开发者 https://www.devze.com 2023-01-09 20:31 出处:网络
It\'s a bit hard to search for it.This might ac开发者_Go百科tually 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

It's a bit hard to search for it. This might ac开发者_Go百科tually 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
0

精彩评论

暂无评论...
验证码 换一张
取 消