Ruby Limit / Take / First - limit sometimes or ignore
I have the following method:
Now sometimes I want the limit attribute to be ignored
Therefore the .take method would be ignored, at the moment I do not know
how to do this gracefully. As setting to nil errors the code.
Any help appreciated - new to ruby.
def articlesByCategory( category, extensions = [ "md" ], limit = 3 )
# Check category is an array
if !category.kind_of?(Array)
category = [ category ]
end
# Create Return Array
ret = []
# Get the resources that are
sitemap.resources.select { |r| ( category & Array( r.data.category )
).present? }.take( limit ).each do |a|
ret << a
end
# Return
ret
end
No comments:
Post a Comment