Last active
August 29, 2015 14:27
-
-
Save nenadjaja/f2a265c14060b6dd76e3 to your computer and use it in GitHub Desktop.
group_by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is my array | |
posts = [{"name"=> "Post1", "start_on"=>"2015-08-11 10:50:00"}, {"name"=>"Post2", "start_on"=>"2015-08-11 10:50:00"}, {"name"=> "Post3", "start_on"=>"2015-08-14 11:00:00"}, {"name"=> "Post4", "start_on"=>"2015-08-14 11:00:00"}] | |
# this method should group posts by start_on property | |
def group(posts) | |
posts.group_by { |p| | |
puts "TEST" | |
puts p.inspect | |
Time.parse(p['start_on']) | |
} | |
end | |
result = group(posts) | |
puts "RESULT: #{result}" | |
# the issue is that the 'result' is a hash whose keys are Time objects. There is no way for me to access that hash, cause I need the keys to be Strings or Symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment