Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Created August 17, 2016 19:37
Show Gist options
  • Save brunojppb/a1e3bd34a2bcd558a430f487951b5a9b to your computer and use it in GitHub Desktop.
Save brunojppb/a1e3bd34a2bcd558a430f487951b5a9b to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
def listar_usuarios(quantidade, my_proc)
uri = URI('http://jsonplaceholder.typicode.com/users')
response = Net::HTTP.get(uri)
JSON.parse(response)
my_proc.call(quantidade)
yield JSON.parse(response) if block_given?
puts "Finalizando listagem de usuarios"
end
debug = Proc.new { |variavel| puts "Debugando Variavel #{variavel}" }
listar_usuarios 10, debug do |response|
puts "Total de usuarios: #{response.size}"
end
listar_usuarios 10, debug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment