#ruby - 09 January 2019
« Back 1 day Forward 1 day »
[08:14:10] za1b1tsu: Anyone using reek as a linter. So I have this method in a module. The module is a collection of methods that generate random data and the method generates a random letter. Reek complains about: UtilityFunction
[08:14:30] za1b1tsu: I mean a UtilityFunction should be in a module, correct? Where should I put it then
[09:10:06] za1b1tsu: I'm researching best practises to use custom errors, and I see that usually they are put in lib/my_app/exceptions.rb
[09:10:56] za1b1tsu: but what if an exception is tied to a certain module/class, do I define the exception in the module/class definition or do I still put in lib/my_app/exceptions.rb?
[09:23:20] za1b1tsu: tbuehlmann, I really like the idea of lib/my_app/exceptions.rb instead of having exceptions all other the place. But this means I should have more generic error classes
[11:20:45] canton7: RougeR, for the same reason that 'workers = result.dig(:work, :workers); workers += `' "doesn't work"
[11:21:09] canton7: in that it increments the 'workers' variable, not the value of result[:work][:workers]
[11:35:45] phaul: so as canton7 said. Plus apart from += doesn't modify as it's just a shorthand for .. = .. + .., integers cannot be modified anyway. there is no way to monkey patch a method into Integer that modifies the value of self
[11:58:30] phaul: there must be a further magic that makes that work. namely it calls =. because  returns the same object as dig, so there is no difference there.
[12:03:50] canton7: well, '+=' will expand to 'result[:work][:workers] = result[:work][:workers] + 1'
[12:10:01] phaul: yeah, it's quite invlolved. (result.(:work)).=(:workers, (result.(:work)).(:workers).+(1))) if im parsing it correctly
[15:27:09] RougeR: trying to get a worker to register its queue as a key in redis when it is brought online
[16:26:44] dviola: I've wrote some code to "normalize" some text but I'm not exactly proud of my normalize method, I was wondering if I can get some help :P
[16:31:33] dviola: mostly I'm trying to refactor this method because I'm calling #each 5 times, it feels kinda wrong
[16:48:40] dviola: I changed it to this: https://gist.github.com/diegoviola/f9fed0e74fe286a5430b0249a569e601
[17:19:35] phaul: dviola: you might not even like this rewrite, but my attempt: https://gist.github.com/phaul/be4256516ee5c0917fb57eded580303d
[17:34:02] phaul: dviola: I made my changes mainly following the ideas from here: https://www.deconstructconf.com/2018/sandi-metz-polly-want-a-message
[17:43:29] havenwood: dviola: I agree with the extract method refactoring. You might consider Regexp with named captures. Something like: https://dpaste.de/7BDT
[17:45:22] havenwood: dviola: I think it'd be nicer to assign @result to the return value of #flat_map and #map rather than shoveling.
[18:34:50] mspo: is there a nicer way to do this part? https://gist.github.com/phaul/be4256516ee5c0917fb57eded580303d#file-x-rb-L26
[18:37:03] phaul: mspo: Sandi calls these or wrapper objects of these factories, and she talks about pushing the conditional out as far as possible (out or up the stack). But she can't avoid having them
[18:42:47] phaul: mspo, undeniably we introduce more classes and more complexity at the surface level, in exchange eliminating all conditional code paths from everywhere, apart from 1 top level factory dispatch
[18:47:23] phaul: alhtough I don't agree with sandi that this should be applied all the time, but in her example and here as well I think it fits
[20:26:26] twobitsprite: Can Rakefiles be aware of non-file target such as docker images, etc? I'm considering moving away from Makefiles, and one of the things I have to do in make is touch files after building images so make can know what needs to be rebuilt.
[23:47:39] SeepingN: Has there been a change in ruby/rails around ruby 2.2.3 where the console no longer returns a value for something unless you use puts to print it out?