I love how in Ruby doing class DoesStuffService def call(x, y) # ... end end is good design but if you do def do_stuff(x, y) end you're a monster
-
-
Replying to @sgrif
Problem with second one is that it's adding the function to Object's instance_methods. So monkey patching + no namespacing. It's good for scripts, but iffy for apps and shouldn't be done in a lib. The first one actually has this problem, too, but it's added to Object's constants.
2 replies 0 retweets 1 like -
Replying to @josh_cheek @sgrif
I think people probably prefer the first one because you can then namespace the rest of your constants within that one toplevel module/class, which you can't do with functions in Ruby. Anyway, my alternative of preference is `do_stuff = lambda { |x, y| }`
1 reply 0 retweets 0 likes -
-
Replying to @sgrif @josh_cheek
Note: I'm not saying if you could that would be good. You're now in the C world of namespacing. But since we don't have any sort of scoped imports, we're already there. `http://Foo.do _bar` isn't meaningfully different from `foo_do_bar`.
1 reply 0 retweets 0 likes -
Replying to @sgrif @josh_cheek
There's no equivalent of `use foo::do_bar` that doesn't muck with some global state.
1 reply 0 retweets 1 like -
Replying to @sgrif
Josh Cheek Retweeted Josh Cheek
Check this out
https://twitter.com/josh_cheek/status/1085646399880847360 …Josh Cheek added,
Josh Cheek @josh_cheekThis is super fascinating. https://github.com/digital-fabric/modulation … Not sure it can work generally since, it'd require buyin from all your dependencies, but it's still super fascinating! Also learned today that `Module#instance_eval` will define constants inside that module rather than on Object!1 reply 0 retweets 0 likes -
Replying to @josh_cheek
That's pretty neat. What I really want though is the ability to import un-namespaced functions.
1 reply 0 retweets 0 likes -
Replying to @sgrif
It does that, here's an example: Function is defined/exported here: https://github.com/digital-fabric/modulation/blob/2615d8d9acc05a5fad5a2f3e3153a6d8925dad5a/examples/callable/factorial.rb … And imported/invoked here: https://github.com/digital-fabric/modulation/blob/master/examples/callable/app.rb …
1 reply 0 retweets 0 likes -
Replying to @josh_cheek
I guess `.()` is probably as close as we can ever get
1 reply 0 retweets 0 likes
https://gist.github.com/sgrif/4d1a066b8dc6de90d6696aeeeefb6483 … is the TL;DR of "I wish I could do this API in Ruby nicely"
-
-
Replying to @sgrif
Check this one out: https://gist.github.com/JoshCheek/5123ccf6255a91e607de382e042b8f6a …pic.twitter.com/5Ksdi8p5wa
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.