« Back to channel list

#ruby - 03 September 2018

« Back 1 day Forward 1 day »
[00:04:08] JamJam_kid: has joined #ruby
[00:11:49] bmurt: has joined #ruby
[00:26:45] bmurt: has joined #ruby
[00:41:14] dbz: has joined #ruby
[00:47:28] Azure: has joined #ruby
[00:50:03] dbz: has joined #ruby
[01:25:10] tdy: has joined #ruby
[02:18:33] apeiros: has joined #ruby
[02:21:03] nicesignal: has joined #ruby
[02:24:19] arescorpio: has joined #ruby
[02:31:04] jp: has joined #ruby
[02:31:12] eckhardt: has joined #ruby
[02:43:43] jenenliu: has joined #ruby
[02:55:55] dbz: has joined #ruby
[02:58:40] eckhardt: has joined #ruby
[03:03:11] jenenliu: has joined #ruby
[03:10:38] braincrash: has joined #ruby
[03:30:41] blobsson: has joined #ruby
[03:31:23] blobsson: in ruby on rails I have a problem where I have 2 threads running code at the same time. Is there a way to block other instances / check if an instance is already running in the same code
[03:39:21] dellavg_: has joined #ruby
[03:42:29] Paraxial: has joined #ruby
[03:49:49] woodruffw: sounds like a mutex is what you want? https://ruby-doc.org/core-2.5.1/Mutex.html
[04:11:47] knight33: has joined #ruby
[04:17:32] Paraxial: has joined #ruby
[04:22:37] Paraxial: has joined #ruby
[04:32:41] Paraxial: has joined #ruby
[04:40:21] jjman: has left #ruby: ("WeeChat 1.6")
[04:48:21] dbz: has joined #ruby
[04:50:39] cgfbee: has joined #ruby
[04:59:45] dbz: has joined #ruby
[05:02:46] Paraxial: has joined #ruby
[05:07:02] Paraxial: has joined #ruby
[05:09:00] MoritaShinobu: has joined #ruby
[05:21:01] esrse: has joined #ruby
[05:24:40] dbz: has joined #ruby
[05:28:04] doubledup: has joined #ruby
[05:34:43] Paraxial: has joined #ruby
[05:37:14] madhatter: has joined #ruby
[05:45:13] _whitelogger: has joined #ruby
[05:48:25] MoritaShinobu: has joined #ruby
[05:54:53] Paraxial: has joined #ruby
[06:00:09] Paraxial: has joined #ruby
[06:07:40] Paraxial: has joined #ruby
[06:09:36] reber: has joined #ruby
[06:11:21] snickers: has joined #ruby
[06:11:34] dionysus69: has joined #ruby
[06:14:00] Paraxial: has joined #ruby
[06:15:38] jenenliu_: has joined #ruby
[06:24:10] Paraxial: has joined #ruby
[06:31:43] MoritaShinobu: has joined #ruby
[06:31:53] LACampbell: has left #ruby: ("WeeChat 2.0.1")
[06:31:55] Paraxial: has joined #ruby
[06:42:36] aufi: has joined #ruby
[06:43:28] d^sh: has joined #ruby
[06:45:15] jokke__: has joined #ruby
[06:48:22] ineb: has joined #ruby
[07:01:04] kapil___: has joined #ruby
[07:06:06] aupadhye: has joined #ruby
[07:21:39] yohji: has joined #ruby
[07:33:20] mikecmpbll: has joined #ruby
[07:34:19] aupadhye: has joined #ruby
[07:44:41] clemens3: has joined #ruby
[07:46:21] alex```: has joined #ruby
[07:46:59] alex```: What is the best practise to tweak a value with a control flow?
[07:47:19] alex```: data = get
[07:47:25] aupadhye: has joined #ruby
[07:47:28] alex```: if options[:pretty]
[07:47:47] alex```: data[:a] = ...
[07:48:01] alex```: data[:b] = data[:b].to_human_size
[07:48:19] alex```: tap is recommended?
[07:48:33] alex```: get.tap do |data|
[07:48:42] alex```: if options[:pretty]
[07:48:58] alex```: data[:a] = data[:a].to_human_size
[07:52:58] clorisu: has joined #ruby
[07:53:37] tristanp: has joined #ruby
[07:55:31] azerin: has joined #ruby
[07:56:53] mikecmpbll: has joined #ruby
[07:58:22] sysvalve: has joined #ruby
[07:58:58] ineb: alex```: it doesnt really matter, but you can write data[:a] = data[:a].to_human_size if options[:pretty]
[08:05:19] azerin: has joined #ruby
[08:08:17] apeiros: alex```: dude, gist
[08:14:08] Quiz: has joined #ruby
[08:33:12] lxsameer: has joined #ruby
[08:34:52] azerin__: has joined #ruby
[08:46:08] dbz: has joined #ruby
[08:47:40] pwnd_nsfw: has joined #ruby
[08:51:25] desperek: has joined #ruby
[08:54:25] tristanp: has joined #ruby
[08:55:58] MoritaShinobu: has joined #ruby
[08:57:40] Beams: has joined #ruby
[09:01:07] roshanavand: has joined #ruby
[09:10:52] Paraxial: has joined #ruby
[09:11:56] roshanavand: has joined #ruby
[09:16:35] Mike11: has joined #ruby
[09:37:32] clorisu: has joined #ruby
[09:47:36] azerin: has left #ruby: ("Bye")
[09:47:44] Paraxial: has joined #ruby
[09:58:25] roshanavand: has joined #ruby
[10:12:25] MoritaShinobu: has joined #ruby
[10:15:59] DTZUZO: has joined #ruby
[10:17:10] jottr: has joined #ruby
[10:37:49] clorisu: has joined #ruby
[10:43:27] Paraxial: has joined #ruby
[10:49:54] AJA4350: has joined #ruby
[10:52:56] anikras: has joined #ruby
[11:04:25] dbz: has joined #ruby
[11:09:03] aufi: has joined #ruby
[11:18:18] arekushi: has joined #ruby
[11:18:50] prestorium: has joined #ruby
[11:20:19] prestorium: Hi all. Anyone using Net/SSH with Windows' OpenSSH? Not git's SSH, but Windows' SSH. I'm trying to make Net/SSH to recognise ssh-agent running under windows
[11:20:40] prestorium: So far, it is always trying to get pageant (putty's agent)
[11:23:20] drale2k_: has joined #ruby
[11:57:10] tristanp: has joined #ruby
[12:06:44] clemens3: has joined #ruby
[12:11:09] augcesar: has joined #ruby
[12:11:11] mikecmpbll: has joined #ruby
[12:13:02] sysvalve: has joined #ruby
[12:16:07] Paraxial: has joined #ruby
[12:47:18] prestorium: has joined #ruby
[12:51:30] prestorium: Hi all. Anyone using Net/SSH with Windows' OpenSSH? Not git's SSH, but Windows' SSH. I'm trying to make Net/SSH to recognise ssh-agent running under windows
[12:51:32] prestorium: So far, it is always trying to get pageant (putty's agent)
[13:02:45] mikecmpbll: has joined #ruby
[13:03:29] MyMind: has joined #ruby
[13:24:50] aufi: has joined #ruby
[13:44:48] prestorium: Dumb question: is UNIXSocket defined on windows?
[13:47:40] prestorium: has joined #ruby
[13:48:12] ineb: prestorium: you mean local sockets AF_UNIX?
[13:48:37] ineb: its available in recent windows releases
[13:48:59] prestorium: ineb I don't know. I'm using Windows 10 and I'm trying to use openssh-ssh-agent named pipe
[13:50:23] ineb: prestorium: regarding your initial question, net/ssh is pure ruby afaik
[13:51:14] prestorium: ineb yes, it is. So I'm trying to monkey patch it so it can work like I want/need :)
[13:57:23] ineb: prestorium: yeah, i looked at the source and they only support pageant from putty
[13:58:15] tristanp: has joined #ruby
[13:59:01] prestorium: ineb yeah... I saw that. But I, in my naïvety, think it should be pretty easy to make it work using openssh on windows as well. That's what I'm trying to do.
[14:02:07] ineb: prestorium: i would assume so aswell. on windows, i would check if i have UNIXSocket available in ruby, then patch out the win32 checks in https://github.com/duerst/net-ssh/blob/master/lib/net/ssh/authentication/agent/socket.rb
[14:02:36] ineb: or just overwrite Net::SSH::Authentication::PLATFORM for a quick hack
[14:04:09] prestorium: ineb this is exactly what I'm doing. :) Except that I'm pretty sure that UNIXSocket is not defined on windows... I took a look at socket/lib/socket.rb, and it requires socket.so. There is no explicit definition of UNIXSocket
[14:04:31] prestorium: So, I'm guessing that socket.so have some #ifdef macro... :(
[14:18:07] prestorium: has joined #ruby
[14:18:52] prestorium: has joined #ruby
[14:19:43] prestorium: has joined #ruby
[14:20:51] ineb: prestorium: okay, ssh-agent on windows exposes a named pipe instead of a UNIX Socket, have you looked at that?
[14:21:17] prestorium: ineb yes. But I'm not sure how to use a named pipe with ruby
[14:21:30] prestorium: That's why I was trying to use it as an unix socket
[14:21:38] ineb: prestorium: well, you cant use a UNIX Socket either if ssh-agent does not creates one
[14:22:03] ineb: or talks to one
[14:22:09] prestorium: ineb well... if a named pipe were a socket... haha
[14:22:51] ineb: maybe https://github.com/chef/win32-pipe
[14:22:54] prestorium: that was my train of thought: "I will make something like UNIXSocket.open("\\.\pipe\openssh-ssh-agen") and call it a day"
[14:23:30] prestorium: I saw win32-pipe... But it has been 2 years since the last update. So I think it is not being used anymore. Perhaps because there is an alternative
[14:26:09] ineb: prestorium: you just need something that does #read #send and #close to a named pipe
[14:27:51] ineb: prestorium: and provide your custom socket factory to Net::SSH::Authentication::Agent#connect!
[14:28:18] ineb: looks like you does not need to patch anything that way
[14:28:41] prestorium: ineb yeah... you're right
[14:36:01] drale2k_: has joined #ruby
[14:51:23] darix: has joined #ruby
[14:54:05] rippa: has joined #ruby
[14:56:24] redlegion: has joined #ruby
[15:02:02] bmurt: has joined #ruby
[15:03:24] conta2: has joined #ruby
[15:04:38] MoritaShinobu: has joined #ruby
[15:07:21] cek: has joined #ruby
[15:19:58] prestorium: has joined #ruby
[15:27:28] Inline: has joined #ruby
[15:40:03] prestorium: has joined #ruby
[15:41:00] darix: has joined #ruby
[15:45:52] wildermind: has joined #ruby
[15:56:44] hays: has joined #ruby
[15:58:20] teej: has joined #ruby
[15:58:58] tristanp: has joined #ruby
[16:02:40] lomex: has joined #ruby
[16:05:42] hays_: has joined #ruby
[16:06:38] nowhere_man: has joined #ruby
[16:06:39] psmolen: has joined #ruby
[16:10:28] eddof13: has joined #ruby
[16:13:27] lxsameer: has joined #ruby
[16:14:18] Dbugger: has joined #ruby
[16:18:03] hays: has joined #ruby
[16:23:09] lxsameer: has joined #ruby
[16:33:12] lxsameer: has joined #ruby
[16:39:06] Zaab1t: has joined #ruby
[16:43:09] lxsameer: has joined #ruby
[16:44:14] thejs: has joined #ruby
[16:44:53] dionysus69: has joined #ruby
[16:46:01] samort7: has joined #ruby
[16:46:55] samort7: Can anyone tell me why .map! isn't working here?
[16:46:57] samort7: https://codeshare.io/5MyO7R
[16:47:16] samort7: `Line 43: in `block in max_increase_keeping_skyline': undefined method `map!' for #<Enumerator: [3, 0, 8, 4]:each_with_index> (NoMethodError)`
[16:50:30] apeiros: samort7: because your expression returns an Enumerator, and Enumerator does not define map!, only map.
[16:51:11] apeiros: I don't know why you use map anyway there
[16:51:11] samort7: apeiros: I am not sure I understand
[16:51:23] apeiros: I'm sure you don't understand :)
[16:51:38] apeiros: what do you expect the map! to do there?
[16:51:39] samort7: apeiros: I was googling how to change an array as you iterate through it and all the stack overflow answers said to use map
[16:51:43] doubledup: has joined #ruby
[16:51:50] apeiros: how to change an *array*. you don't have an array there.
[16:52:08] apeiros: row <-- array, row.each_with_index <-- not an array
[16:52:28] samort7: oh, right. That makes sense
[16:52:38] samort7: So how do I change the values as I iterate through them?
[16:53:14] lxsameer: has joined #ruby
[16:54:21] apeiros: >> a = [1,2,3]; a.map!.each_with_index do |e,idx| e*idx end; a
[16:54:33] apeiros: eval.in dead again :(
[16:54:38] apeiros: # => [0,2,6]
[16:54:41] Nicmavr: has joined #ruby
[16:55:35] samort7: so the problem was where i was calling .map!
[16:57:09] samort7: apeiros: I think I was thrown off by this question where he calls map __after__ .each_with_index
[16:57:15] samort7: https://stackoverflow.com/questions/4697557/how-to-map-with-index-in-ruby
[16:58:51] apeiros: with map, that works. with map!, it doesn't.
[16:59:09] apeiros: since as said, the return value of each_with_index is Enumerator, not Array. and there's no Enumerator#map!
[16:59:31] samort7: aah, interesting
[16:59:44] RougeR: has joined #ruby
[17:00:11] RougeR: sim using minitest and my test will pass intermittently
[17:00:25] RougeR: sometimes i get Uninitalized constant FooClass
[17:00:29] samort7: apeiros: I guess I need to read up on what an enumerator is
[17:00:31] RougeR: sometimes i get full passing
[17:00:38] RougeR: any ideas
[17:00:57] RougeR: NameError: uninitialized constant CopyFileFromS3
[17:01:21] RougeR: Where CopyFileFrom S3 is a class that is being initialized fine when i run the tests again
[17:01:36] RougeR: i know tests run in randomized orders, but im not sure why this is happening
[17:03:11] lxsameer: has joined #ruby
[17:04:04] AJA4350: has joined #ruby
[17:05:32] RougeR: >NameError: uninitialized constant CopyFileFromS3
[17:07:31] SuperLag: has joined #ruby
[17:11:48] cek: has left #ruby: ()
[17:13:17] lxsameer: has joined #ruby
[17:14:16] EvilJStoker: has joined #ruby
[17:23:13] lxsameer: has joined #ruby
[17:25:43] dellavg_: has joined #ruby
[17:30:05] akemot: has joined #ruby
[17:33:32] lxsameer: has joined #ruby
[17:37:17] SuperLag: has joined #ruby
[17:39:28] pyrmont: samort7: I was looking for information about Enumerators the other day and found this article (https://medium.com/@farsi_mehdi/the-enumerable-module-in-ruby-part-i-745d561cfebf) and its sequel helpful.
[17:43:12] lxsameer: has joined #ruby
[17:44:22] nikivi: has joined #ruby
[17:53:13] lxsameer: has joined #ruby
[17:55:17] thejs: has joined #ruby
[17:59:52] tristanp: has joined #ruby
[18:03:29] lxsameer: has joined #ruby
[18:03:32] redlegion: has joined #ruby
[18:13:10] lxsameer: has joined #ruby
[18:14:49] mroutis: has joined #ruby
[18:23:12] lxsameer: has joined #ruby
[18:33:19] lxsameer: has joined #ruby
[18:34:59] dbz: has joined #ruby
[18:43:21] lxsameer: has joined #ruby
[18:49:41] dionysus70: has joined #ruby
[18:53:14] lxsameer: has joined #ruby
[18:55:25] psmolen: has joined #ruby
[19:03:27] lxsameer: has joined #ruby
[19:03:55] psmolen: has joined #ruby
[19:10:48] Sp4rKy: has joined #ruby
[19:11:57] TheMoonMaster_: has joined #ruby
[19:17:10] redlegion: has joined #ruby
[19:17:12] HansPeterIngo: has joined #ruby
[19:18:43] kapil___: has joined #ruby
[19:19:27] noodle: has joined #ruby
[19:27:57] psmolen: has joined #ruby
[19:28:36] lenqbit: has joined #ruby
[19:33:01] HansPeterIngo: I have been trying to follow the rubocop styling rules for the 3rd time. But I cannot get my head around how splitting up methods like these could be a good idea. https://gist.github.com/HansPeterIngo/6d2116b0d18e2559f53c463e38524937
[19:38:38] HansPeterIngo: It would be propably the easiest to just use some plain sql-statement in a string. But aren't then those dsl / builder gems always against the ruby style guide? Because they lead in my experience to long methods.
[19:39:55] Inline: has joined #ruby
[19:40:17] RougeR: has joined #ruby
[19:40:58] psmolen: has joined #ruby
[19:41:21] Inline: has joined #ruby
[19:45:13] dbz: has joined #ruby
[19:50:52] dbz: has joined #ruby
[19:51:36] DTZUZO: has joined #ruby
[19:53:21] thejs: has joined #ruby
[20:05:12] sameerynho: has joined #ruby
[20:14:29] jp: has joined #ruby
[20:17:26] c0ncealed2: has joined #ruby
[20:18:38] dbz: has joined #ruby
[20:21:49] dbz: has joined #ruby
[20:32:43] clorisu: has joined #ruby
[20:32:47] JJonah: Consider an immutable value object with lazy, memoized methods for derived attributes: https://eval.in/1053602. It's tedious to create the memoizations like `@some_attr ||= ...` for every single method, especially when I know beforehand (since the object is immutable) that I want *every* method to work like that. Ideally I could just `extend ValueObject` as the first line under the class definition, and this would happen
[20:32:47] JJonah: automatically for every method. That is, every method would get wrapped by a memoizer. But I can't find a good meta-programming technique to accomplish this (other than creating a class method like `def_memoized` that I'd use every time instead of `def` -- a solution I'm not crazy about). Any ideas?
[20:37:13] lenqbit: has joined #ruby
[20:38:00] dbz: has joined #ruby
[20:45:50] danguita: has joined #ruby
[20:56:43] apeiros: JJonah: there are gems out there providing memoization for methods, you should probably take a look
[20:57:22] apeiros: personally, if I'd implement that, I'd use a prefixed method: `memoized def foo; complex_calc; end`
[20:57:46] apeiros: and the impl. would be to have a prepended module.
[20:59:10] orbyt_: has joined #ruby
[21:09:50] JJonah: apeiros: how would that work syntactically? (ie, `memoized def foo`) Googling "prefixed ruby method" isn't turning up anything. What it suggests is exactly what I want (meaning I want to treat an ordinary `def` defined method as a first-class object, and then either wrap it or alter it to provide the memoization functionality. But I thought ruby wasn't capable of this...
[21:10:28] apeiros: memoized is a class method, def foo returns :foo, that's passed to memoized as argument
[21:11:13] apeiros: prepended module would mean wrapping (via inheritance chain)
[21:12:24] apeiros: basically: `def memoized(method_name); class_eval("def method_name(*args); @_#{method_name} ||= super"; end); end`
[21:15:13] Guest58115: has joined #ruby
[21:15:31] JJonah: apeiros: TIL `def` returns a symbol... Ok what you did makes sense. I guess the part that screwed with me is I want to be able to address the method as an object (like a `Proc`ish) at the class level, but the concepts of `UnboundMethod` only makes sense in ruby at the instance level. Which (related to my question last night) seems like an arbitrary, unnecessary restriction.
[21:18:42] apeiros: no, UnboundMethod doesn't only make sense at an instance level. quite the opposite.
[21:18:54] apeiros: only a bound method (Method) makes only sense at an instance level.
[21:19:01] apeiros: that's why UnboundMethod#bind exists
[21:23:31] JJonah: apeiros: sorry, that was confusing. I meant that you can't (or I can't figure out how to :) to take an UnboundMethod, alter it (eg, by wrapping it with a memoizer) and then "re-attach" at the class level to its original class. This kind of thing, eg, would be trivial in JS.
[21:24:05] psmolen: has joined #ruby
[21:25:08] apeiros: I don't think altering functions is trivial in JS. I'm curious about that technique.
[21:25:11] JJonah: (other than using `class_eval` as you did, ofc). But that requires manipulation via strings.
[21:25:38] apeiros: define_method takes an UnboundMethod, but doesn't let you alter it.
[21:25:39] JJonah: apeiros: in JS you can just wrap it. and then put it back on the object
[21:25:45] apeiros: wrap isn't alter.
[21:25:49] apeiros: wrapping is trivial in ruby too.
[21:26:40] JJonah: apeiros: So can you do what you did without "eval", but using actual Proc or UnboundMethod objects? That's essentially what I'm asking (and saying is easy in JS)
[21:27:57] apeiros: basically: `def memoized(method_name); ubm = instance_method(method_name); define_method(method_name) do |*args, &block| ubm.bind(self).call(*args, &block); end; end`
[21:28:15] apeiros: essentially the same you'd have to do in JS too (apply/call =~ bind().call())
[21:28:31] apeiros: though if I'd want to do it stringless, I'd do:
[21:29:00] baweaver_away: Oi oi oi, that's a lot of code talk
[21:29:05] lupine: FWIW, we looked at this kind of memoization magic in our codebase, and ran a mile. We just `include Utils::StrongMemoize` and do def x ; strong_memoize { ... } ; end` instead
[21:29:18] baweaver_away: ACTION starts reading through the back traces
[21:29:29] lupine: just because you can, does not mean you should
[21:29:34] apeiros: `def memoized(method_name); define_method(method_name) do instance_variable_get(:"@_#{method_name}") || "instance_variable_set(:"@_#{method_name}", super); end; end`
[21:29:51] apeiros: lupine: yeah, told them to look at gems :)
[21:30:08] lupine: but yes, it's traditional(ish) OO, not prototypes
[21:30:16] apeiros: all my methods btw. don't give a crap about methods which have valid nil/false results
[21:30:30] JJonah: apeiros: i know about the gems. i'm trying to understand it myself and understand the options. also i'm not crazy about the gem interfaces i've looked at.
[21:30:34] lupine: you can emulate javascript behaviour in ruby quite easily by disdaining classes and using hashes everywhere
[21:30:40] baweaver_away: dangit IRC, gimme my nick
[21:30:54] lupine: you can even add prototypes with the `Hash.new {|h,k| h[k] = ... }` idiom
[21:30:59] apeiros: ACTION nicks baweaver's irc
[21:31:10] lupine: or, you know, you could just write in javascript. nodejs exists for people who like to do that
[21:31:12] JJonah: lupine: "by disdaining classes and using hashes everywhere" . I have no desire to do that :)
[21:31:27] lupine: right, so it's not surprising that some things are different
[21:31:29] apeiros: yeah, and you can rebuild ruby's class/module infrastructure in JS (even with JS before ES6)
[21:31:38] lupine: you wouldn't want to though :D
[21:32:30] apeiros: I still did, though. and it was fun. and useful.
[21:32:33] lupine: here's an alternative. How about a Memoizer class that acts as a facade around an object and memoizes methods going through it?
[21:32:54] apeiros: lupine: indiscriminately memoize all methods?
[21:32:55] JJonah: "so it's not surprising that some things are different"... my issue isn't that "thing are different". it's that i wasn't able to do something i thought i should be able to do. but apeiros last replies are basically the answer i was looking for.
[21:32:58] apeiros: seems wasteful
[21:33:39] JJonah: "indiscriminately memoize all methods" not if you're in the context of an immutable value object which was the jumping off point of the discussion.
[21:33:43] apeiros: would work for the given parameters, though (immutable objects - though memoization basically breaks that)
[21:34:00] lemur: Decorators
[21:34:08] JJonah: "immutable objects - though memoization basically breaks that" -- it does not.
[21:34:24] lemur: They're hell on inheritance chains though
[21:34:26] apeiros: the moment you store the memoized value in the object, yes, yes, you do :)
[21:34:29] JJonah: only in a technical sense, not in a conceptual sense
[21:34:56] lupine: apeiros: one could optionally implement a list of memoable methods
[21:34:59] JJonah: because you are guaranteed that a pure function on immutable params will always return the same value
[21:35:22] apeiros: lupine: yeah, that'll be rather close to my suggestion of `memoized` using a prepended module.
[21:35:28] JJonah: the object is still immutable in every meaningful way. the "memoizatoin" mutation is purely a caching strategy
[21:35:43] apeiros: just that you create the list by prepending `memoized` to the method def :)
[21:35:43] lemur: If that's what you're going for, there are ways to make it "pure"
[21:35:58] lemur: Though it's insanely pedantic in Ruby to insist on absolute purity
[21:35:59] dbz: has joined #ruby
[21:36:24] apeiros: that's either ruby in puberty, or pure ruby.
[21:36:28] lemur: referential purity, sure. If the outside caller doesn't know you're doing something impure it matters very little.
[21:36:53] JJonah: lemur: i don't want you mean by that. but immutable value objects are very useful in ruby. i don't see any pedantry about them
[21:37:10] apeiros: my point mostly being: you can't use .freeze to ensure the immutability of memoizing objects if you use those objects as the storage for the memoized values.
[21:37:15] lemur: consider this implementation of count_by: def count_by(list, &fn) list.reduce(Hash.new(0)) { |h,v| h[fn[v]] += 1; h } end
[21:37:20] JJonah: "referential purity, sure. If the outside caller doesn't know you're doing something impure it matters very little." exactly
[21:37:30] lemur: It mutates, but it doesn't really matter
[21:37:38] apeiros: and personally, I tend to actually freeze my immutable objects to get early and loud explosions.
[21:37:52] lemur: because the outside caller has no idea it did anything, so you get hybrid FP with some speed gains in Ruby.
[21:38:04] JJonah: apeiros: that breaks lazy evaluation which is a very good thing and what i'm after here.
[21:38:27] apeiros: JJonah: it doesn't. it just puts restrictions on your available toolset.
[21:38:54] lupine: looks a bit like https://gitlab.com/snippets/1750773
[21:39:25] lupine: 'though ISTR you should implement responds_to or something as well
[21:39:29] JJonah: apeiros: how do you get lazy evaluation out of truly frozen object?
[21:39:42] lemur: Now then, the proposed memo solution looks pure, but technically is not. Question is do we want to be pedantic about that detail, or relish in the fact that it still follows the contract of idempotency?
[21:39:49] JJonah: (lazy evaluation and caching i should say)
[21:39:56] apeiros: JJonah: you don't store the result in the frozen object.
[21:40:06] lupine: heh, my solution works for that
[21:40:07] apeiros: see WeakHash
[21:40:20] JJonah: lemur: "relish in the fact that it still follows the contract of idempotency" i want to relish
[21:40:35] lemur: ACTION wants a hot dog now
[21:40:45] apeiros: ACTION is already full, thank you for your consideration
[21:41:32] lemur: apeiros: what was that hackery where you could do this nice long block before a method and it'd redefine the next one to "decorate" it?
[21:41:49] lemur: Api Pie does it everywhere: https://github.com/Apipie/apipie-rails
[21:42:01] jjman: has joined #ruby
[21:42:24] apeiros: lemur: I'd assume they use method_added
[21:42:29] JJonah: apeiros: I want the object to cache its own values. The pattern of my original paste is exactly what I want, I just want to avoid the repeated `||=` boilerplate.
[21:42:39] apeiros: at least iirc that's how rake does it
[21:42:44] apeiros: (desc + task)
[21:42:49] jjman: What's a good book to learn ruby these days?
[21:43:09] lemur: jjman: what's your skill level?
[21:43:14] apeiros: JJonah: @memoized={} in initialize
[21:43:18] apeiros: remember, freeze ain't deep
[21:43:31] lemur: and what goals do you have?
[21:43:32] lemur: Also see the books list in the channel topic
[21:43:47] apeiros: JJonah: though I see zero reason for that requirement. seems rather arbitrary.
[21:43:56] JJonah: apeiros: sure, but that's just an implementation detail. i fail to see how that's fundamentally different from the pattern i posted.
[21:44:10] apeiros: which pattern did you post?
[21:44:38] apeiros: you mean @foo ||=?
[21:44:50] JJonah: "for that requirement. seems rather arbitrary." -- which requirement. i meant this pattern: https://eval.in/1053602
[21:45:01] apeiros: "I want the object to cache its own values"
[21:45:03] apeiros: this requirement
[21:45:21] jjman: lemur: have solid compsci foundations I guess, my goal is Rails ;) to create a server-side-rendered html web app in a short time
[21:45:29] apeiros: why do you bother where the cache is?
[21:45:37] apeiros: it's an implementation detail
[21:45:46] apeiros: (unless you fuck up, of course :D)
[21:45:47] JJonah: apeiros: yes, i think we're crossing wires. if the internal hash is doing it, it's still "the object caching its own values"
[21:45:53] lemur: jjman: Start around "Eloquent Ruby"
[21:46:06] JJonah: the only POV we're considering is the object's contract from the outside
[21:46:10] apeiros: JJonah: I see no issue with an external weakhash storing it either
[21:46:20] lemur: It teaches Ruby from a perspective of already knowing programming
[21:46:21] apeiros: both variants allow you to freeze your object
[21:46:30] apeiros: allowing you to enforce the immutability contract
[21:46:42] JJonah: apeiros: external to the object itself? that would be bad imo. an internal hash, that's fine.
[21:46:43] apeiros: maintaining your requirement of caching/lazy evaluation
[21:46:56] jjman: lemur: Ok, will check out it, have you read the pickaxe boo? seems appropiate too
[21:47:06] jjman: s/boo/book/
[21:47:09] lemur: It's a bit basic
[21:47:13] apeiros: define external. the only things internal to an object are variables. never objects.
[21:47:28] apeiros: so IMO that notion is pointless.
[21:47:30] JJonah: apeiros: we're just using the word differently
[21:47:31] jjman: lemur: ok yeah, I like details
[21:47:31] lemur: Books: https://goo.gl/wpGhoQ
[21:47:32] lemur: I wrote this list a while back
[21:47:33] lemur: give it a look.
[21:47:34] lemur: There's a Rails one too
[21:47:48] lemur: Rails Book List: http://goo.gl/SGklzh
[21:47:51] apeiros: JJonah: I see that differently. but well, it's bed time for me.
[21:47:55] JJonah: i mean the client of the object should not have to deal with the object AND a 2nd object that does the caching
[21:48:09] apeiros: JJonah: why do you think the client would have to?
[21:48:14] apeiros: as said, it's an implementation detail
[21:48:28] JJonah: apeiros: i am like 95% sure we're agreeing
[21:48:44] lupine: note that `@foo ||=` doesn't work well if hte result is `false` or `nil`, yet still expensive to compute
[21:48:57] jjman: lemur: yeah, got the pickaxe book from your first link, thanks
[21:49:33] JJonah: lupine: yes, that's a good point. you can get around that if need be though.
[21:49:42] lupine: aye, it's easily forgotten is all
[21:50:15] lupine: I still like mine. the internal vs. external question is by the by - ruby doesn't store data like that
[21:50:29] tty: has joined #ruby
[21:50:34] lupine: all we're asking is whether the memozied class holds a reference to its memoizer or not
[21:50:36] JJonah: lupine: yours being the method_missing version?
[21:50:55] JJonah: and yes, i agree that is an implementation detail
[21:51:00] dbz: has joined #ruby
[21:51:39] JJonah: to me the question of `||=` vs a private hash is of little import.
[21:51:47] lupine: it can be useful to hold such a reference - for instance, you might want to clear memoized values based on some interaction or another. but you can always include the reference if you need it
[21:51:57] JJonah: lupine: sure
[21:54:11] bomb: has joined #ruby
[21:55:55] JJonah: lupine: the only thing i don't like about the method_missing snippet you posted is that I have to create my object and then wrap it. I can't just issue the directive at the class level. Or have I misunderstood?
[21:56:43] jjman: lemur: the rails guide seem pretty good I guess? why are they not on your list?
[21:56:55] lemur: Probably forgot
[21:57:07] lemur: Throw a comment up with a link to it
[21:57:31] lemur: It's not unusual that I miss one or two good ones :P
[21:58:45] bomb: hi i'm learning ruby
[21:59:11] jjman: bomb: me too!
[21:59:37] lemur: It's the bomb :D
[22:00:37] lemur: bomb: What's your skillset? What do you want to make?
[22:01:01] lemur: See the booklist in the channel topic
[22:01:41] bomb: mobile and desktop GUI lemur. but first i need to learn ruby well. it's a little different than what i knew
[22:02:03] lemur: Eloquent Ruby is a good start
[22:03:11] baweaver: Aha! Got my nick back
[22:03:13] baweaver: There we go.
[22:03:25] JJonah: lemur: do you use your Mf gem often in your own work? I found it a few weeks after write a similar gem (https://github.com/jonahx/pretty_ruby) and thought it was quite clever.
[22:03:31] JJonah: baweaver: ^^
[22:03:32] baweaver: lemur === baweaver
[22:03:47] bomb: Eloquent Ruby alright
[22:03:49] baweaver: I use Xf and Qo a ton
[22:04:08] baweaver: Xf is real danged handy for Swagger JSON debugging, Jira responses, and other such things
[22:05:33] jp: has joined #ruby
[22:05:38] baweaver: Qo for a lot of ETL type tasks to trim down some real nasty logic
[22:05:59] lupine: JJonah: one option would be to override the `new` method to return an always-memoized instance
[22:06:10] baweaver: I used Mf to get around having to monkey patch anything
[22:06:11] lupine: or to add a `build_memoized` class method that does the smae
[22:06:16] lupine: lots of ways to do this
[22:06:53] bomb: do you know what's the reasoning behind this quote? "Ruby is designed to make programmers happy."
[22:07:02] JJonah: baweaver: i want to alias it to X though so i can do `map {&X + 5}` etc... :)
[22:07:32] baweaver: Nothing stopping you from `X = Mf` :)
[22:07:32] JJonah: bomb: the language is intended to be fun to write and pretty to read.
[22:07:33] baweaver: All the one letter names were taken
[22:07:37] baweaver: I ended up getting a hold of Any too
[22:07:46] baweaver: Any is an always true match
[22:07:59] baweaver: https://rubygems.org/gems/any
[22:09:06] baweaver: For Qo you can do this: [1, 's', 3.0, 4].select(&Qo[Integer, 1..4])
[22:09:18] mroutis: has joined #ruby
[22:09:31] bomb: JJonah: hmm sounds cool. is it really fun in practice?
[22:09:31] baweaver: If you had tuples or objects it gets real handy
[22:09:58] baweaver: people.select(&Qo[name: Any, age: 20..30])
[22:10:17] baweaver: Though it'll hard require that key to exist
[22:11:03] baweaver: #ruby-offtopic is a fun join if you want to see shenanigans outside of just Ruby in Ruby.
[22:11:27] JJonah: baweaver: nice.
[22:11:55] baweaver: Anyone else going to RubyConf this year?
[22:12:07] baweaver: If you are you get to see me making lemur voices on stage :D
[22:12:30] clorisu: has joined #ruby
[22:13:18] mikecmpbll: has joined #ruby
[22:13:19] JJonah: bomb: that's a hard question to answer. the short is: it's a nice language, but not perfect.
[22:13:32] baweaver: I certainly have fun
[22:14:19] baweaver: http://rubyconf.org/program#session-716 - Lemur talk! :D
[22:14:28] thejs: has joined #ruby
[22:14:46] Nicmavr: has joined #ruby
[22:18:32] JJonah: baweaver: "They're hell on inheritance chains though"... just scrolled up to copy something and noticed this. Don't you mean "inheritcance chains are hell in themselves"?
[22:18:42] baweaver: method_added
[22:21:48] bomb: JJonah: fair. hopefully it brings the fun back, because i'll be using Ruby for non-serious projects :)
[22:22:05] JJonah: bomb: what do you program in now?
[22:23:50] bomb: JJonah: i mostly do java and python professionally. got some free time now, wanted to try Ruby for some small mobile and desktop apps
[22:24:03] bomb: i'll be using rubymotion and shoes
[22:26:35] JJonah: bomb: i personally think ruby is more fun than both of those languages, especially java. though tbh it's not _that_ different from python.
[22:28:03] bomb: JJonah: speaking of java, does jruby work well? it doesn't hurt to have an access to an ocean of libraries
[22:28:39] JJonah: bomb: haven't use it much myself, but i think it's fairly mature.
[22:29:19] lupine: I've got production experience of jruby. it's pretty solid
[22:29:47] lupine: sometimes surprising things happen, and the gap between jruby and cruby is a lot narrower now than it was back then. I probably wouldn't use it again
[22:30:06] baweaver: TruffleRuby is the new kid on the block there.
[22:30:42] bomb: oh glad to hear. JavaFX + JRuby with Shoes-esque interface might be fun
[22:30:54] bomb: TruffleRuby is that new Graal thing?
[22:31:26] pabs: has joined #ruby
[22:38:25] nowhere_man: has joined #ruby
[22:44:11] Nicmavr: has joined #ruby
[22:45:40] dbz: has joined #ruby
[22:47:29] bomb: interesting. RPG Maker XP uses Ruby for scripting. LibGDX + JRuby also works, apparently. and there is also Gosu
[22:48:22] baweaver: RMXP and one of the later versions
[22:48:24] baweaver: it uses JS now.
[22:48:31] AJA4351: has joined #ruby
[22:48:34] baweaver: Though it was also some variant of 1.9.2
[22:48:38] baweaver: and was pretty sketch
[22:48:43] bomb: yeah, i have the MV version. i wish XP was on sale
[22:49:05] baweaver: I used to hang around a lot of RPG maker forums as lemur forever ago.
[22:50:26] bomb: was it fun?
[22:51:54] baweaver: Yep. Some good times way back then.
[22:52:14] baweaver: KobrasRealm, RpgRpgRevolution, and a few others
[22:52:23] baweaver: Some DreamInCode too, but that was more generic.
[22:55:21] bomb: i heard many people still use XP because of the existing Ruby scripts
[23:07:33] clorisu: has joined #ruby
[23:13:44] psmolen: has joined #ruby
[23:15:50] Guest58115: has joined #ruby
[23:21:32] apeiros: has joined #ruby
[23:22:42] LiftLeft3: has joined #ruby
[23:23:50] jackrandom: has joined #ruby
[23:26:33] orbyt_: has joined #ruby
[23:29:51] clorisu: has joined #ruby
[23:31:55] dviola: has joined #ruby
[23:46:19] Freshnuts: has joined #ruby
[23:47:41] johnny56: has joined #ruby