Skip to content

Instantly share code, notes, and snippets.

@fivetwentysix
Last active December 10, 2015 00:29
Show Gist options
  • Save fivetwentysix/4351887 to your computer and use it in GitHub Desktop.
Save fivetwentysix/4351887 to your computer and use it in GitHub Desktop.
face palm
def options_from_hashes_for_select(hashes, value, display, selected=nil)
attributes = 'attr_accessor ' + hashes.first.map do |key, value|
"#{key.downcase.to_sym.inspect}"
end.join(', ')
eval <<-RUBY
class X
#{attributes}
end
RUBY
collection = hashes.map.each do |hash|
x = X.new
hash.each do |key, value|
x.send("#{key.downcase}=", value)
end
x
end
options_from_collection_for_select(collection, value, display, selected)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment