Skip to content

Instantly share code, notes, and snippets.

@hackling
Created November 7, 2014 00:23
Show Gist options
  • Save hackling/bc88ff321c52701eb158 to your computer and use it in GitHub Desktop.
Save hackling/bc88ff321c52701eb158 to your computer and use it in GitHub Desktop.

I've been dealing with large views a lot lately, when looking at individual rows, I find that it dumps to much data on the screen. I found myself using the following pattern a lot.

activity.attributes.slice(*activity.attributes.keys.grep /search_term/

I think it would be cool to instead just go

activity.find_columns(:budget)
activity.find_columns(:budget, :hours)
module ColumnFinder
extend ActiveSupport::Concern
def find_columns(*search_terms)
search_terms.map { |search_term|
attributes.slice(*attributes.keys.grep(/#{search_term}/))
}.reduce({}, :merge)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment