Skip to content

Instantly share code, notes, and snippets.

@gary
Last active April 22, 2016 20:07
Show Gist options
  • Save gary/7f0fbc067b3c127209d27323ddfaab41 to your computer and use it in GitHub Desktop.
Save gary/7f0fbc067b3c127209d27323ddfaab41 to your computer and use it in GitHub Desktop.
#map invocation wtf
open(url) { |channel| JSON.parse(channel.read) }.map do |channel_data|
attrs = channel_data.values_at("id", "key", "name", "description",
"asset_url", "created_at", "updated_at")
Channel.new(*attrs).tap(&:pick_stream_url)
end
# => #<Enumerator: [{"json"=>"attrs"}, { "json"=> "attrs"},{"json"=>"attrs"}]:map>
open(url) { |channel| JSON.parse(channel.read) }.map { |channel_data|
attrs = channel_data.values_at("id", "key", "name", "description",
"asset_url", "created_at", "updated_at")
Channel.new(*attrs).tap(&:pick_stream_url)
}
# => [#<Channel:0x007ff7b388ecc8>, #<Channel:0x007ff7b38e2508>, #<Channel:0x007ff7b2a38048>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment