1

I wrote the following code:

def report_view_classes
  [
    Hourdiff,
    AverageTimeForFirstReferrals,
    CountZipCodeByUserids,
    FirstRentForUsers,
  ]
end

def load_views
  report_view_classes.each do |report_view_class|
    report_view_class.create
  end

but rubocop gives me following warning:

C: Pass &:create as an argument to each instead of a block.
  report_view_classes.each do |report_view_class

I am confused what to do

coreyward
  • 77,547
  • 20
  • 137
  • 166
Hasan
  • 21
  • 5
  • 1
    Possible duplicate of [Ruby ampersand colon shortcut](https://stackoverflow.com/questions/1961030/ruby-ampersand-colon-shortcut) – coreyward Jul 17 '17 at 16:32
  • 1
    In such cases it's always best to refer to the source: http://www.rubydoc.info/gems/rubocop/0.26.1/RuboCop/Cop/Style/SymbolProc. – medik Jul 17 '17 at 16:39

1 Answers1

1

Ruby has a shorthand for simple blocks.

["apple", "pear", "grape"].map { |fruit| fruit.upcase }

# This does the same thing with less code:

["apple", "pear", "grape"].map(&:upcase)
michaeltomer
  • 445
  • 3
  • 7