Created
June 14, 2019 03:45
-
-
Save pocke/62a796b7c43240a38e7fbe319d459f47 to your computer and use it in GitHub Desktop.
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
require "net/http" | |
require "json" | |
class Pipeline < BasicObject | |
def self.start | |
new | |
end | |
def initialize | |
@prev = nil | |
end | |
def >(right) | |
if right.respond_to?(:call) | |
@prev = right.call(@prev) | |
else | |
@prev = right | |
end | |
self | |
end | |
def method_missing(name, *args) | |
@prev = @prev.__send__(name, *args) | |
self | |
end | |
end | |
Pipeline.start | |
|>>"https://api.github.com/repos/ruby/ruby" | |
|>> URI.:parse | |
|>> Net::HTTP.:get | |
|>> JSON.:parse | |
|> fetch("stargazers_count") | |
|>> "Ruby has %d stars".:% | |
|>> self.:puts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment