0

Seems like this would be a fairly common pattern - declaring the array and returning it:

def self.show_day_rows(days, month, year, offset)
  daylines=[]
  1.step(days,7).each do |line_starts_with|
    daylines << CalDay.line_of_day_nums(month, year, line_starts_with, offset)
  end
  daylines
end

Is there a way to shorten this but still be legible?

2
  • You probably want to ask this on Code Review. It's for these sort of questions. Commented Oct 19, 2013 at 1:03
  • 1
    This question appears to be off-topic because it belongs on Code Review Commented Oct 19, 2013 at 3:37

2 Answers 2

2
def self.show_day_rows(days, month, year, offset)
  1.step(days,7).map do |line_starts_with|
    CalDay.line_of_day_nums(month, year, line_starts_with, offset)
  end
end
Sign up to request clarification or add additional context in comments.

Comments

0

A slight variant of @tihorn's answer:

def self.show_day_rows(days, month, year, offset)
  1.step(days,7).inject([]) do |daylines, line_starts_with|
    daylines << CalDay.line_of_day_nums(month, year, line_starts_with, offset)
  end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.