« Back to channel list

#ruby - 14 July 2018

« Back 1 day Forward 1 day »
[00:07:23] beefjoe: has joined #ruby
[00:09:21] cadillac_: has joined #ruby
[00:09:46] konsolebox: has joined #ruby
[00:24:47] cagomez: has joined #ruby
[00:25:10] lxsameer: has joined #ruby
[00:26:41] herbmillerjr: has joined #ruby
[00:31:55] Freshnuts: has joined #ruby
[00:41:23] mynameisdebian: has joined #ruby
[00:48:33] bonhoeffer: has joined #ruby
[00:55:17] Sammichmaker: has joined #ruby
[01:05:00] lxsameer: has joined #ruby
[01:12:57] nowhereman_: has joined #ruby
[01:14:56] lxsameer: has joined #ruby
[01:15:22] dmgk: has joined #ruby
[01:16:34] mynameisdebian: has joined #ruby
[01:17:46] graphene: has joined #ruby
[01:19:00] jottr: has joined #ruby
[01:22:42] Tempesta: has joined #ruby
[01:26:57] SunnyLumenz: has joined #ruby
[01:27:15] graphene: has joined #ruby
[01:38:01] jenrzzz: has joined #ruby
[01:38:02] jenrzzz: has joined #ruby
[01:44:51] lele: has joined #ruby
[01:45:24] jrafanie: has joined #ruby
[01:45:50] darkhanb: has joined #ruby
[01:46:56] tdy1: has joined #ruby
[01:47:40] _Freshnuts_: has joined #ruby
[01:51:39] kryptoz: has joined #ruby
[01:54:54] lxsameer: has joined #ruby
[01:58:04] giz|lazer: has joined #ruby
[02:11:14] Emmanuel_Chanel: has joined #ruby
[02:18:24] MagePsycho: has joined #ruby
[02:26:02] pauliesaint: has joined #ruby
[02:30:14] _whitelogger: has joined #ruby
[02:38:20] graphene: has joined #ruby
[02:39:27] pauliesaint: has joined #ruby
[02:39:53] lxsameer: has joined #ruby
[02:41:10] graphene: has joined #ruby
[02:44:04] kapil___: has joined #ruby
[02:44:57] lxsameer: has joined #ruby
[02:52:43] c0ncealed2: has joined #ruby
[02:53:27] Puffball: has joined #ruby
[02:53:51] sepp2k: has joined #ruby
[02:56:45] \void: has joined #ruby
[03:00:23] cadillac_: has joined #ruby
[03:05:30] JJonah: i'm trying to determine an array's levels of nesting. the best i've got so far is: https://eval.in/1036351. is there a terser, preferably more functional, alternative?
[03:09:29] graphene: has joined #ruby
[03:10:28] braincrash: has joined #ruby
[03:11:16] sepp2k1: has joined #ruby
[03:11:34] Emmanuel_Chanel: has joined #ruby
[03:12:27] Emmanuel_Chanel: has joined #ruby
[03:13:29] elomatreb: JJonah: You could abuse Array#flatten, that gets you a relatively simple solution
[03:14:21] jenrzzz: has joined #ruby
[03:14:28] jenrzzz: has joined #ruby
[03:14:36] elomatreb: Something like https://eval.in/1036353
[03:19:32] JJonah: elomatreb: thanks, i like that a bit better
[03:19:44] graphene: has joined #ruby
[03:20:46] elomatreb: Complexity should be something like O(n*m) where n is the totally flattened array size and m is the nesting depth
[03:24:58] lxsameer: has joined #ruby
[03:26:21] jottr: has joined #ruby
[03:28:25] graphene: has joined #ruby
[03:35:15] lxsameer: has joined #ruby
[03:35:43] Nicmavr: has joined #ruby
[03:36:14] akaiiro: has joined #ruby
[03:36:33] havenwood: With 2.5's predicate matching: 0.step.find { |n| a.flatten(n).none? Array }
[03:37:46] elomatreb: Oh that's even better
[03:38:13] JJonah: havenwood: nice
[03:40:09] graphene: has joined #ruby
[03:41:11] graphene: has joined #ruby
[03:44:38] graphene: has joined #ruby
[03:45:08] lxsameer: has joined #ruby
[03:47:58] evdubs_: ruby novice here; if you would want to do something in ruby where you read in a .rb file, look at all the functions, and add automatic log statements to the functions showing the local vars, is there a library or something you would look to use?
[03:49:10] evdubs_: ideally i could just have a macro that adds the log statements when i want them but i don't think ruby supports macros?
[03:50:45] elomatreb: evdubs: That gets very difficult. You could instead try a metaprogramming-based solution, e.g. with the method_added hook
[03:50:46] djbkd: has joined #ruby
[03:51:45] n13z: has joined #ruby
[03:57:54] jottr: has joined #ruby
[03:58:46] gix-: has joined #ruby
[03:59:56] ur5us: has joined #ruby
[04:04:56] lxsameer: has joined #ruby
[04:24:59] jzhu: has joined #ruby
[04:25:49] akaiiro: has joined #ruby
[04:30:28] podlech: has joined #ruby
[04:33:33] suukim: has joined #ruby
[04:42:17] ciscam: has joined #ruby
[04:49:58] lxsameer: has joined #ruby
[04:54:37] graphene: has joined #ruby
[05:03:49] user3: has joined #ruby
[05:05:22] alfiemax: has joined #ruby
[05:09:57] kedibasi: has joined #ruby
[05:12:03] akaiiro: has joined #ruby
[05:16:24] donofrio: has joined #ruby
[05:23:04] DTZUZO: has joined #ruby
[05:30:10] lxsameer: has joined #ruby
[05:35:23] graphene: has joined #ruby
[05:37:42] lxsameer: has joined #ruby
[05:39:44] alex```: has joined #ruby
[05:42:42] nowhere_man: has joined #ruby
[05:42:57] lxsameer: has joined #ruby
[05:44:38] karapetyan: has joined #ruby
[05:55:01] tag: has joined #ruby
[05:58:03] ur5us: has joined #ruby
[05:58:28] Es0teric: has joined #ruby
[06:02:44] willthechill: has joined #ruby
[06:05:12] jottr: has joined #ruby
[06:06:30] kedibasi: has joined #ruby
[06:07:59] jenrzzz: has joined #ruby
[06:08:00] jenrzzz: has joined #ruby
[06:12:34] mynameisdebian: has joined #ruby
[06:13:33] Freshnuts: has joined #ruby
[06:22:38] lxsameer: has joined #ruby
[06:25:14] za1b1tsu_: has joined #ruby
[06:31:43] apeiros_: has joined #ruby
[06:32:58] lxsameer: has joined #ruby
[06:34:17] dellavg: has joined #ruby
[06:37:45] rippa: has joined #ruby
[06:40:07] jottr: has joined #ruby
[06:41:24] jasmith: has joined #ruby
[06:41:50] konsolebox: has joined #ruby
[06:42:39] lxsameer: has joined #ruby
[06:48:07] schleppel: has joined #ruby
[06:49:42] alem0lars: has joined #ruby
[07:06:23] naftilos76: has joined #ruby
[07:09:15] conta: has joined #ruby
[07:12:20] jasmith: has joined #ruby
[07:22:37] lxsameer: has joined #ruby
[07:33:43] karapetyan: has joined #ruby
[07:35:58] alfiemax: has joined #ruby
[07:38:41] kedibasi: has joined #ruby
[07:40:46] skarlso: has joined #ruby
[07:54:13] Kilo`byte: has joined #ruby
[08:02:37] lxsameer: has joined #ruby
[08:10:59] kedibasi: has left #ruby: ()
[08:11:00] karapetyan: has joined #ruby
[08:16:44] za1b1tsu_: has joined #ruby
[08:25:01] amar: has joined #ruby
[08:27:14] universa1: has joined #ruby
[08:31:17] snickers: has joined #ruby
[08:31:56] bkxd: has joined #ruby
[08:34:05] clemens3: has joined #ruby
[08:34:18] segy: has joined #ruby
[08:35:54] alireza: has joined #ruby
[08:36:43] alireza: my timezone is +04:30
[08:36:47] alireza: Time.new(2000, 7, 1).dst? => true
[08:37:08] alireza: but Time.new(2000, 7, 1, 0, 0, 0, "+04:30").dst? => false
[08:37:41] alireza: Time.new(2000, 7, 1, 0, 0, 0, "+04:30") == Time.new(2000, 7, 1) => true
[08:38:12] alireza: why when I define timezone and hours, minutes and seconds dst? returns false
[08:38:38] sepp2k: has joined #ruby
[08:45:06] biberu: has joined #ruby
[08:46:52] jottr: has joined #ruby
[08:47:40] lxsameer: has joined #ruby
[08:48:43] cadillac_: has joined #ruby
[08:53:13] Megamosaren: has joined #ruby
[08:54:18] Mia: has joined #ruby
[08:54:18] Mia: has joined #ruby
[08:56:08] karapetyan: has joined #ruby
[09:01:18] dhollinger: has joined #ruby
[09:01:58] shinnya: has joined #ruby
[09:04:38] beefjoe: has joined #ruby
[09:10:26] ciscam: has joined #ruby
[09:11:14] kapil___: has joined #ruby
[09:20:17] jottr: has joined #ruby
[09:22:19] alfiemax: has joined #ruby
[09:27:41] lxsameer: has joined #ruby
[09:35:58] alfiemax: has joined #ruby
[09:48:59] psychicist__: has joined #ruby
[09:50:09] TinkerT: has joined #ruby
[09:53:07] Alec: alireza - although gone hopefully did something valuable you all saw
[09:53:24] Alec: There are bastard evil people out there living in a + x.5 hour timezone (for an integer x)
[09:53:48] Alec: There even more evil bastards living in + x.25 and +x.75 timezones!
[09:53:59] Alec: NEVER DO TIMEZONES YOURSELF
[09:56:07] ellcs: has joined #ruby
[09:58:38] desperek: has joined #ruby
[10:03:25] jottr: has joined #ruby
[10:05:01] _aeris_: has joined #ruby
[10:06:15] reber: has joined #ruby
[10:07:42] lxsameer: has joined #ruby
[10:15:37] jottr: has joined #ruby
[10:17:21] RougeR: has joined #ruby
[10:17:21] RougeR: has joined #ruby
[10:17:58] lxsameer: has joined #ruby
[10:18:01] ciscam: has joined #ruby
[10:20:33] sameerynho: has joined #ruby
[10:21:15] _aeris_: has joined #ruby
[10:28:24] alfiemax: has joined #ruby
[10:32:37] lxsameer: has joined #ruby
[10:34:01] cliq: has joined #ruby
[10:46:31] bonhoeffer: has joined #ruby
[10:46:42] schneider: has joined #ruby
[10:52:30] _aeris_: has joined #ruby
[11:00:40] jamesaxl: has joined #ruby
[11:02:12] RougeR: ive been asked to create a simple api for a tech test
[11:02:18] RougeR: ive finished it and its wrapped up in a class
[11:02:24] RougeR: should this be wrapped up inside a module or not?
[11:06:57] AJA4350: has joined #ruby
[11:07:08] psychicist__: has joined #ruby
[11:12:37] lxsameer: has joined #ruby
[11:13:36] ciscam: has joined #ruby
[11:22:38] lxsameer: has joined #ruby
[11:27:02] lomex: has joined #ruby
[11:34:16] beefjoe: has joined #ruby
[11:34:43] Zaab1t: has joined #ruby
[11:43:02] schneider: has joined #ruby
[11:43:03] bonhoeffer: has joined #ruby
[11:46:15] alex```: has joined #ruby
[11:48:01] d^sh: has joined #ruby
[11:48:09] shinnya: has joined #ruby
[11:56:41] jinie: has joined #ruby
[11:56:58] bkxd: has joined #ruby
[12:02:41] lxsameer: has joined #ruby
[12:07:09] Es0teric: has joined #ruby
[12:07:46] lxsameer: has joined #ruby
[12:08:35] za1b1tsu_: has joined #ruby
[12:13:07] bsamorim: has joined #ruby
[12:17:01] alfiemax: has joined #ruby
[12:19:30] Defenestrate: has joined #ruby
[12:19:31] Defenestrate: has joined #ruby
[12:20:09] ellcs: has joined #ruby
[12:21:14] RougeR: has joined #ruby
[12:21:14] RougeR: has joined #ruby
[12:27:07] gnufied: has joined #ruby
[12:42:17] bonhoeffer: has joined #ruby
[12:44:08] jottr: has joined #ruby
[12:45:20] guyyoghurt: has joined #ruby
[12:45:38] mprelude: has joined #ruby
[12:47:30] jottr_: has joined #ruby
[12:47:37] lxsameer: has joined #ruby
[12:48:25] al2o3-cr: has joined #ruby
[12:52:51] kobain: has joined #ruby
[13:00:57] bonhoeffer: has joined #ruby
[13:02:44] jottr: has joined #ruby
[13:03:42] ptx0: has joined #ruby
[13:06:07] fmcgeough: has joined #ruby
[13:28:06] desperek: has joined #ruby
[13:28:28] beefjoe: has joined #ruby
[13:32:04] bonhoeffer: has joined #ruby
[13:32:38] lxsameer: has joined #ruby
[13:34:51] alfiemax: has joined #ruby
[13:40:22] Es0teric: has joined #ruby
[13:43:08] mprelude: has joined #ruby
[13:43:53] Defenestrate: has joined #ruby
[13:43:54] Defenestrate: has joined #ruby
[13:44:55] soniya29: has joined #ruby
[13:46:04] graphene: has joined #ruby
[14:12:39] lxsameer: has joined #ruby
[14:13:42] kryptoz: has joined #ruby
[14:22:20] jasmith: has joined #ruby
[14:29:34] lomex: has joined #ruby
[14:34:07] alex```: has joined #ruby
[14:35:25] lele: has joined #ruby
[14:36:06] Mike11: has joined #ruby
[14:37:14] jmcgnh: has joined #ruby
[14:40:50] graphene: has joined #ruby
[14:43:59] ellcs: has joined #ruby
[14:48:26] Aukai: has joined #ruby
[14:49:45] Aukai: has joined #ruby
[14:52:39] lxsameer: has joined #ruby
[14:52:42] rkoller: has joined #ruby
[14:57:46] lxsameer: has joined #ruby
[15:01:29] Es0teric: has joined #ruby
[15:13:31] reber: has joined #ruby
[15:13:33] reber__: has joined #ruby
[15:13:44] graphene: has joined #ruby
[15:14:10] white_lilies: has joined #ruby
[15:14:52] Zaab1t: has joined #ruby
[15:17:09] DLSteve: has joined #ruby
[15:19:02] lomex: has joined #ruby
[15:25:37] Asher: has joined #ruby
[15:35:04] dellavg: has joined #ruby
[15:37:39] lxsameer: has joined #ruby
[15:44:09] venmx: has joined #ruby
[15:46:50] graphene: has joined #ruby
[15:58:27] za1b1tsu_: has joined #ruby
[16:07:15] phenom: has joined #ruby
[16:16:29] FernandoBasso: has joined #ruby
[16:17:29] cadillac_: has joined #ruby
[16:20:30] Dimik: has joined #ruby
[16:22:39] lxsameer: has joined #ruby
[16:23:56] herbmillerjr: has joined #ruby
[16:34:31] kryptoz: has joined #ruby
[16:42:55] karapetyan: has joined #ruby
[16:45:33] alex```: has joined #ruby
[16:53:58] za1b1tsu_: has joined #ruby
[17:03:35] npgm: has joined #ruby
[17:07:36] lxsameer: has joined #ruby
[17:12:21] m27frogy: has joined #ruby
[17:13:57] samosaphile: has joined #ruby
[17:29:02] jrafanie: has joined #ruby
[17:29:07] Megamosaren: has joined #ruby
[17:32:49] amar: has joined #ruby
[17:40:08] bonhoeffer: has joined #ruby
[17:42:07] kliq: has joined #ruby
[17:44:48] mynameisdebian: has joined #ruby
[17:47:39] lxsameer: has joined #ruby
[17:47:45] FernandoBasso: Inside method defined inside a module, is there a self.<something> that would show the name of the module?
[17:48:31] FernandoBasso: Like, in a class method, I can do self.class and it shows the name of the class in which the method is defined. Can I show the name of the module in which the module is defined in a similar fashion?
[17:48:40] apeiros: self.class.ancestors will contain it
[17:49:06] FernandoBasso: I see. Thanks.
[17:49:37] apeiros: but since a method is always invoked in the context of the receiver, there's nothing which will tell you "this is the method defined in module X"
[17:50:22] apeiros: well, to a degree you can use source_location and/or method(__method__).owner, both have their issues and limitations.
[17:50:26] apeiros: what do you try to achieve?
[17:51:38] FernandoBasso: Nothing in particular. Just trying to understand self better, and the relation between modules and classes.
[17:52:12] Mike11: has joined #ruby
[17:52:39] apeiros: self is the object in which's (whose?) context the current code is executed.
[17:52:58] lxsameer: has joined #ruby
[17:53:41] orbyt_: has joined #ruby
[17:53:47] FernandoBasso: So far, I figure it is, in some ways, similar to `this' in javascript. Its value depending on how the code is executed, and not set in stone upon definition.
[17:54:26] apeiros: it's exactly as `this` in js. js just differs in when context of `this` changes.
[17:57:52] amar: has joined #ruby
[17:59:31] FernandoBasso: I see. All right. Thanks.
[18:02:39] lxsameer: has joined #ruby
[18:04:08] Mike11: has joined #ruby
[18:07:48] lxsameer: has joined #ruby
[18:11:55] bak1an: has joined #ruby
[18:15:02] bonhoeffer: has joined #ruby
[18:17:41] lxsameer: has joined #ruby
[18:21:48] alex```: has joined #ruby
[18:22:25] Alec: apeiros: "for which is the context the code executes in"
[18:23:36] Alec: Or "provides the"
[18:24:21] isene: Using the short form of File.write( file, content ) instead of File.open, is there a way to create the file with permissions 644 at the same time, or do I then have to stick with File.open to achieve that?
[18:24:57] Alec: isene: you very probably don't want to do that, by opening it first and getting a handler, if the file is moved or deleted the handler follows it and will work (that is it isn't really deleted until all handlers are gone)
[18:25:48] dviola: has joined #ruby
[18:25:54] Alec: You can use the creat system call to do this (and usually open with O_CREAT - you can also supply permissions by oring the relevant flags
[18:26:15] salasrod: has joined #ruby
[18:26:52] Alec: isene: the importance of "create and open" vs "create then open" is the race condition, if you say run touch or something to make the file, there is a chance that some prick - say me - could delete it and put a link in its place directing you whereever I want you to write - or some shit
[18:27:21] Alec: For RTFMing you want "man 2 creat"
[18:27:32] Alec: That's right, they saved one letter.
[18:27:40] lupine: note that you can also open with a flag that refuses to open a link
[18:27:47] lupine: which is a nice way to avoid the race
[18:27:53] lupine: not cross-platform though
[18:28:23] Alec: That doesn't totally cover you though
[18:28:26] Alec: But yeah
[18:29:40] Alec: isene: a more common mistake is to CHECK IF THE FILE EXITS - and then act, this is also very racy (and a "common" exploit of this class) - you must use creat or open with O_CREAT and set it to fail if it exists.
[18:31:16] isene: I don't think the race conditions is of any concern here. What I have now is: File.open("npcs/town.npc", File::CREAT|File::EXCL|File::RDWR, 0644) { |fl| fl.write f } But looking to simplify, I would want File.write("npcs/town.npc", f) but with the chmod as 644 (File.write without anything doesn't give 644 rights)
[18:31:16] Alec: lupine: do you know a lot about POSIX calls or was it like just that bit?
[18:31:28] Alec: Because I have a problem maybe we could bitch about together or solve
[18:31:32] bonhoeffer: has joined #ruby
[18:31:45] lupine: I can try
[18:32:06] lupine: isene: you also want O_NOFOLLOW
[18:32:13] lupine: whatever that is in ruby
[18:32:22] Alec: isene: most file calls are "atomic" - take for example rename, there is never an instance where both the original and target names are valid, for example. So you want to do your opening as ONE call - never two
[18:32:31] Alec: No he doesn't
[18:33:22] Alec: lupine: isene you want :
[18:33:23] Alec: If the file does not exist it will be created.
[18:33:27] Alec: from the manual
[18:33:35] Alec: If the file does not exist it will be created.
[18:33:47] Alec: Sorry ctrl+shift+c to copy silly me
[18:33:48] Alec: O_EXCL Ensure that this call creates the file: if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
[18:33:56] Alec: O_EXCL Ensure that this call creates the file: if this flag is specified in conjunction with O_CREAT, and pathname already exists, then open() will fail.
[18:34:15] Alec: Sorry it wouldn't be more than 6 lines if I hadn't screwed up c&p
[18:34:16] Alec: When these two flags are specified, symbolic links are not followed: if pathname is a symbolic link, then open() fails regardless of where the symbolic
[18:34:16] Alec: link points to.
[18:34:32] GodFather: has joined #ruby
[18:34:33] Alec: lupine: ^
[18:34:34] lupine: CREAT + EXCL is ok, yeah
[18:34:48] Alec: There's no point to no-follow
[18:35:00] Alec: Without EXCL in your scenario
[18:35:05] lupine: if you're just doing an open() of an existing file you don't want to be a symlink, there is
[18:35:09] Alec: ALSO I see he already specified it.
[18:35:22] Alec: Symlinks are good
[18:35:23] lupine: I jumped in without context, it's a lot of fun :)
[18:35:29] lupine: sometimes good, sometimes a security risk
[18:35:41] Alec: You must hate /usr/share :P
[18:35:48] lupine: it's fine when they're owned by root
[18:36:03] Alec: Anyway yeah I have an issue with ordered durable writes
[18:36:08] Alec: How can I do it?
[18:36:31] lupine: I don't think you can, really. not reliably
[18:36:40] lupine: the filesystem or hardware can always override your hints
[18:36:42] Alec: It is a bitch
[18:36:55] Alec: But the range fsync rarely can be used
[18:37:13] Alec: So you have to fsync the directory AND the file
[18:37:33] Alec: This leads to like 12 fsyncs to do a durable journalled write start to end
[18:38:14] Alec: ACTION is ALWAYS chasing the D - but sometimes he needs to ask "this is good, but at what cost did I achieve this?"
[18:40:08] lupine: you can open O_DIRECT or O_SYNC of course, but it's still all just hints
[18:40:33] Alec: VERY difficult to test too.
[18:40:45] lupine: you can also mmap() the file and use msync()
[18:41:09] lupine: you *will* need MS_SYNC
[18:41:37] fmcgeough: has joined #ruby
[18:42:25] Alec: nah the only way is the two fsycns (which even then may report "it worked" and be lying)
[18:44:46] isene: So - to my original question - is there a way to simply to File.write to achieve what I want?
[18:45:49] Alec: Why do you want to?
[18:46:26] Alec: Just throw in some new lines and say //THESE OPTIONS HAVE TO BE FUCKING SIDE BY SIDE, TOUCH AND I'LL HAVE YOU TOUCHED!
[18:46:41] kliq: has joined #ruby
[18:48:02] balo: language pls
[18:48:36] TomyLobo: has joined #ruby
[18:48:44] GodFather: has joined #ruby
[18:48:52] Alec: balo: a compromise happened there, just FYI - "touched" wasn't my first choice.
[18:49:06] banisterfiend: has joined #ruby
[18:51:42] Alec: Hi banisterfiend
[18:52:16] c0ncealed2: has joined #ruby
[18:53:31] isene: I just wondered if there was a way with File.write instead of File.open ... is there?
[18:55:16] Alec: RTFM m8 - and remember raceconditions are a thing and bad
[18:55:41] Alec: That's why your OS goes through all the extra work to implement these flags
[18:56:07] isene: Alec: There is no race condition possible here. Apart from that point, then... is there a way with File.write?
[18:56:39] Alec: IF there is no race with your way, then ... well there is no race!
[18:57:38] bonhoeffer: has joined #ruby
[18:57:57] isene: Alec: My question was this:
[18:58:18] isene: What I have now is: File.open("npcs/town.npc", File::CREAT|File::EXCL|File::RDWR, 0644) { |fl| fl.write f } But looking to simplify, I would want File.write("npcs/town.npc", f) but with the chmod as 644 (File.write without anything doesn't give 644 rights)
[18:59:04] Alec: isene: you can lead a horse to water but you can't make it drink
[19:00:09] GodFather: has joined #ruby
[19:00:35] isene: Alec: Do you have an answer to my question?
[19:01:04] Alec: isene: I'm saying I've taken you to the water and made you aware of the issues, where to find info and check, now you need to do your part.
[19:02:38] lxsameer: has joined #ruby
[19:03:28] apeiros: isene: to answer your actual question - yes, File.write accepts a mode parameter which allows you to have it created with the mode you want.
[19:03:51] isene: Alec: What you did was to raise a point regarding race conditions - which is fine in and of itself - but my question was not about that. And I fail to see that you have led me to any source answering what I actually asked.
[19:04:02] isene: apeiros: Thank you so much
[19:04:24] apeiros: ah, no, actually that seems to be to allow you to use w, a or r+
[19:04:28] Alec: ACTION poker faces.... "yes, but only if you check the conditions are met"
[19:04:53] hays_: has joined #ruby
[19:05:39] isene: apeiros: So how would my File.write alternative look like to achieve my current File.open way of doing the file write?
[19:06:36] mguex: has left #ruby: ("WeeChat 2.0")
[19:07:46] vutral|kali: has joined #ruby
[19:07:57] apeiros: isene: File.write(path, content, perm: 0644)
[19:08:38] apeiros: note mode but perm was the key. sorry for the confusion.
[19:09:09] GodFather: has joined #ruby
[19:09:47] isene: apeiros: Thanks a bunch. That was a swift, service-minded fly-by on your part.
[19:10:33] apeiros__: has joined #ruby
[19:12:59] GodFather: has joined #ruby
[19:13:53] bonhoeffer: has joined #ruby
[19:21:10] jrafanie: has joined #ruby
[19:26:49] graphene: has joined #ruby
[19:28:09] ellcs: has joined #ruby
[19:30:04] zachk: has joined #ruby
[19:30:05] zachk: has joined #ruby
[19:30:48] GodFather: has joined #ruby
[19:34:53] quobo: has joined #ruby
[19:35:51] foobarbaz_: has joined #ruby
[19:41:03] GodFather: has joined #ruby
[19:41:33] graphene: has joined #ruby
[19:42:47] lxsameer: has joined #ruby
[19:45:10] white_lilies: has joined #ruby
[19:51:16] apeiros: isene: follow up from before, your File::CREAT|File::EXCL|File::RDWR is what would go to the mode kwarg (mode: File::CREAT|File::EXCL|File::RDWR)
[19:54:10] clemens3: has joined #ruby
[19:56:25] bonhoeffer: has joined #ruby
[19:56:55] GodFather_: has joined #ruby
[19:56:58] mynameisdebian: has joined #ruby
[19:57:38] isene: apeiros: Right. Thanks for the follow-up. I have now simplified my code. It's aesthetically cleaner now :-)
[19:57:53] lomex: has joined #ruby
[19:59:48] graphene: has joined #ruby
[20:04:35] GodFather: has joined #ruby
[20:09:59] amar: has joined #ruby
[20:11:44] bonhoeffer: has joined #ruby
[20:13:17] alfiemax: has joined #ruby
[20:16:56] GodFather: has joined #ruby
[20:18:42] akaiiro: has joined #ruby
[20:21:39] graphene: has joined #ruby
[20:22:36] lxsameer: has joined #ruby
[20:23:55] claudiuinberlin: has joined #ruby
[20:24:15] redlegion: has joined #ruby
[20:29:29] ur5us: has joined #ruby
[20:29:49] nowhere_man: has joined #ruby
[20:31:48] graphene: has joined #ruby
[20:31:48] \void: has joined #ruby
[20:32:38] lxsameer: has joined #ruby
[20:33:52] blackwind_123: has joined #ruby
[20:38:48] mynameisdebian: has joined #ruby
[20:39:05] Dimik: has joined #ruby
[20:41:58] clemens3: has joined #ruby
[20:42:38] lxsameer: has joined #ruby
[20:52:40] lxsameer: has joined #ruby
[20:53:11] deadnull: has joined #ruby
[20:53:46] graphene: has joined #ruby
[20:56:15] lomex: has joined #ruby
[20:56:49] JJonah: if you define a lambda within a method, as a helper function relevant only to that method, will the interpreter be smart enough to optimize the lambda so that it's only created once and re-used, or will it be created, thrown away, and garbage collected every time the method is invoked?
[20:58:51] Alec: JJonah: does the lambda have access to any variables that were not passed to it as parameters?
[20:59:14] Alec: eg k=5; f = ->(a,b) { return a+b+k; } <---can it get this k?
[20:59:42] Alec: In that case you will almost certainly get the same lambda each time and let me just test it real quick
[20:59:43] JJonah: Alec: ah, then maybe. i'd be curious for the answer in both cases, if its different
[20:59:57] Alec: If it's different JJonah the lambda has to be "bundled" in with the k
[21:00:22] Alec: You'll get a lambda for each run, carrying its own value of k (well the "type" will carry the data, the lambda code itself will still almost certainly be created once)
[21:00:33] Alec: Join me in #ruby-community time to work with retard-bot
[21:00:38] JJonah: Alec: ty, could you also show me how you are testing it? i wasn't sure how to do it myself and would like to know
[21:00:48] Alec: Join me in #ruby-community time to work with retard-bot
[21:03:46] vipaca: has joined #ruby
[21:05:14] BTRE: has joined #ruby
[21:05:59] apeiros: JJonah: it is likely that e.g. truffleruby will do a better job at optimizing such things. mri tends to be less aggressive in that regard. but there has been a lot of resources spent on improving ruby's performance and thus optimization behavior.
[21:06:06] apeiros: if it's relevant, just bench it.
[21:08:52] d^sh: has joined #ruby
[21:11:17] JJonah: apeiros: yeah, i figured this was basic enough that i actually wanted to know how it worked under the hood though.
[21:12:32] apeiros: while Alec's methodology was flawed over in #ruby-community, we can use the base idea to see that it will at least create a new object every time:
[21:12:34] apeiros: >> def foo; x = ->() { "blah #{Time.now}" }; x.call; x; end; (1..10).map { foo.object_id }.uniq.size
[21:12:36] ruby[bot]: apeiros: # => 10 (https://eval.in/1036677)
[21:13:11] apeiros: (that's for MRI, same for 2.5.1, so that part didn't change there)
[21:14:02] graphene: has joined #ruby
[21:15:10] JJonah: apeiros: good example, although technically wouldn't that prove only that it recreates it "when it needs to". ie, it might only be recreating it because it's smart enough to know the lambda isn't pure and in this case the "natural" behavior would be broken if it kept it around. but in cases where it there were no ill effects it could...
[21:16:00] graphene: has joined #ruby
[21:17:25] white_lilies: has joined #ruby
[21:18:27] JJonah: related question: ignoring the silliness of this example, i was interested in the scoping rules that prevent the following from working: `def fact(n); step = ->(m) { m == 0 ? 1 : m * step(m - 1) }; step.(n) end`. I mean, lambda's have access to local vars, the step var is in local scope...
[21:19:46] amar_: has joined #ruby
[21:19:47] apeiros: JJonah: you can replace the lambda in the example. I'd expect it to be the same.
[21:21:25] apeiros: JJonah: you forgot a dot :)
[21:21:42] apeiros: >> def fact(n); step = ->(m) { m == 0 ? 1 : m * step.(m - 1) }; step.(n) end; fact 6
[21:21:43] ruby[bot]: apeiros: # => 720 (https://eval.in/1036679)
[21:22:24] JJonah: "I'd expect it to be the same." You're right, it is.
[21:23:05] JJonah: apeiros: doh! ty
[21:27:16] JJonah: so the bottom line of all this is: if you have a helper function for one of your methods, you're options are 1. create an inner lambda and eat the inefficiency of it being recreated each call 2. make a private helper method relevant and eat the messiness of having a relevant-to-one-method-only helper method on your class 3. make an object to encapsulate the original method and make the helper method private on _that_ object, and
[21:27:16] JJonah: eat the verbosity
[21:29:56] apeiros: I think I tend to opt for the private method
[21:30:35] JJonah: apeiros: agreed, least of all evils
[21:31:16] JJonah: at least in most cases. if the complexity is high enough 3. becomes worth it.
[21:36:32] vipaca: has joined #ruby
[21:37:23] vipaca: What happened to the Rails channel, why is invite only?
[21:38:04] vipaca: Did they leave for slack or something?
[21:38:41] graphene: has joined #ruby
[21:39:13] vipaca: Thanks @samosaphile I got it not sure why I didn't see it at first
[21:41:10] Caerus: has joined #ruby
[21:42:59] headius: apeiros, JJonah: both JRuby and TR should optimize that case, though TR currently does more to reduce the cost of the closure
[21:43:27] karapetyan: has joined #ruby
[21:43:40] headius: the short answer on MRI is that the code block will be reused but the state around it (local variables, self, etc) goes into a memory structure that has to be allocated and then cleaned up later
[21:44:16] headius: for a simple case JRuby will not allocate as much, and I'm working on getting it to inline and allocate nothing
[21:45:00] JJonah: headius: thx for the info.
[21:47:41] lxsameer: has joined #ruby
[21:53:01] crankharder: has joined #ruby
[21:57:34] zlogan2003: has joined #ruby
[21:57:40] lxsameer: has joined #ruby
[22:07:39] lxsameer: has joined #ruby
[22:10:25] BTRE: has joined #ruby
[22:11:16] RougeR: has joined #ruby
[22:11:17] RougeR: has joined #ruby
[22:13:34] banisterfiend: has joined #ruby
[22:14:33] SunnyLumens: has joined #ruby
[22:20:05] nowhere_man: has joined #ruby
[22:20:49] shinnya: has joined #ruby
[22:23:07] ur5us: has joined #ruby
[22:27:37] lxsameer: has joined #ruby
[22:33:01] tag: has joined #ruby
[22:33:37] ur5us: has joined #ruby
[22:37:23] Some-body_: has joined #ruby
[22:37:47] lxsameer: has joined #ruby
[22:39:47] akaiiro: has joined #ruby
[22:40:26] karapetyan: has joined #ruby
[22:41:55] RougeR: has joined #ruby
[22:41:56] RougeR: has joined #ruby
[22:47:10] jrafanie: has joined #ruby
[22:47:45] almdrx: has joined #ruby
[22:47:46] lxsameer: has joined #ruby
[23:02:38] amar: has joined #ruby
[23:14:33] hphat^: has joined #ruby
[23:14:58] hphat^: has joined #ruby
[23:15:23] hphat^: has joined #ruby
[23:15:48] hphat^: has joined #ruby
[23:16:10] hphat^: has joined #ruby
[23:16:33] hphat^: has joined #ruby
[23:19:50] moei: has joined #ruby
[23:27:37] lxsameer: has joined #ruby
[23:40:49] stairmast0r_: has left #ruby: ("WeeChat 2.1")
[23:48:29] BTRE: has joined #ruby
[23:49:41] ur5us: has joined #ruby