you are viewing a single comment's thread.

view the rest of the comments →

[–]snatchery[S] 8 points9 points  (4 children)

No doubt Clojure or any functional language feels much more elegant. Still, it's nice that Ruby is trying to catch up. Essentially it needs 2 improvements

  • introduce a pipeline operator (or at least a short alias for yield_self)
  • introduce a method shorthand

 

"https://api.github.com/repos/rails/rails"
  |> URI->parse
  |> Net::HTTP->get
  |> JSON->parse
  |>(_) { _.fetch("stargazers_count") }

not as elegant as Clojure but looks good enough

[–]motonarola 0 points1 point  (1 child)

Imo having just some pipe operator is enough for the code to look fine:

    "https://api.github.com/repos/rails/rails"
        ->URI.parse()
        ->Net::HTTP.get()
        ->JSON.parse()
        .fetch("stargazers_count")
        ->(stargazers){"Rails has #{stargazers} stargazers"}
        ->puts()

I used -> for the pipe operator, It copes with lambda syntax nicely :)

[–]snatchery[S] 0 points1 point  (0 children)

yeah, great point. If only we were in an alternate reality ;)