« Back to channel list

#ruby - 22 May 2018

« Back 1 day Forward 1 day »
[00:00:51] bmurt: has joined #ruby
[00:03:46] quuxman: although I'm unclear how to do that
[00:11:37] alfiemax: has joined #ruby
[00:14:07] shinnya: has joined #ruby
[00:14:38] ElFerna: has joined #ruby
[00:14:49] cagomez: has joined #ruby
[00:16:27] sytherax_: has joined #ruby
[00:20:34] quuxman: `Foo.where(...)` is failing with an invalid field error
[00:25:15] alfiemax: has joined #ruby
[00:26:12] sytherax_: has joined #ruby
[00:26:43] guacamole: has joined #ruby
[00:26:43] guacamole: has joined #ruby
[00:31:09] cagomez: has joined #ruby
[00:42:34] karapetyan: has joined #ruby
[00:44:04] cagomez: has joined #ruby
[00:48:30] alfiemax: has joined #ruby
[01:03:06] ElFerna: has joined #ruby
[01:05:59] AndroUser: has joined #ruby
[01:09:39] harrycs: has joined #ruby
[01:11:38] cagomez: has joined #ruby
[01:16:58] AndroUser: has joined #ruby
[01:17:44] giraffe: has joined #ruby
[01:17:56] lowerlight: has joined #ruby
[01:18:57] tpendragon: has joined #ruby
[01:20:54] lowerlight: has joined #ruby
[01:24:17] bmurt: has joined #ruby
[01:28:34] MyMind: has joined #ruby
[02:08:29] t0xik: has joined #ruby
[02:15:45] rivalomega: has joined #ruby
[02:19:02] sanscoeur: has joined #ruby
[02:20:56] Ryzokuken: has joined #ruby
[02:21:48] edwardly: has joined #ruby
[02:21:48] edwardly: has joined #ruby
[02:23:21] sumobob: has joined #ruby
[02:39:57] alfiemax: has joined #ruby
[02:40:51] sumobob: has joined #ruby
[02:44:01] karapetyan: has joined #ruby
[02:44:55] xuyuheng: has joined #ruby
[02:52:22] cagomez: has joined #ruby
[02:55:48] houhoulis: has joined #ruby
[02:57:59] sumobob: has joined #ruby
[02:59:11] kapil___: has joined #ruby
[03:00:10] cadillac_: has joined #ruby
[03:03:30] stairmast0r: has joined #ruby
[03:06:56] rivalomega: has joined #ruby
[03:09:47] safetypin: has joined #ruby
[03:10:17] sysfault: has joined #ruby
[03:12:42] sumobob: has joined #ruby
[03:24:53] alfiemax: has joined #ruby
[03:26:11] cadillac_: has joined #ruby
[03:27:08] guacamole: has joined #ruby
[03:27:08] guacamole: has joined #ruby
[03:27:34] herbmillerjr: has joined #ruby
[03:28:11] sumobob: has joined #ruby
[03:31:42] houhoulis: has joined #ruby
[03:35:14] amar_: has joined #ruby
[03:41:35] sumobob: has joined #ruby
[03:42:54] jsrtr: has joined #ruby
[03:48:24] ramfjord: has joined #ruby
[03:49:26] gix-: has joined #ruby
[03:51:34] ARCADIVS: has joined #ruby
[03:56:12] thapakazi: has joined #ruby
[03:56:22] thapakazi_: has joined #ruby
[04:07:17] Ryzokuken: has joined #ruby
[04:15:55] conr: has left #ruby: ()
[04:16:27] SuperLag: has joined #ruby
[04:22:45] anisha: has joined #ruby
[04:32:43] ciscam: has joined #ruby
[04:33:21] white_lilies: has joined #ruby
[04:41:01] rivalomega: has joined #ruby
[04:41:52] mtkd: has joined #ruby
[04:45:33] karapetyan: has joined #ruby
[05:03:52] Ryzokuken: has joined #ruby
[05:04:06] podlech: has joined #ruby
[05:09:35] howdoi: has joined #ruby
[05:11:20] reber: has joined #ruby
[05:16:28] pabs: has joined #ruby
[05:16:33] DoubleMalt: has joined #ruby
[05:24:04] sidx64: has joined #ruby
[05:29:33] apeiros: has joined #ruby
[05:33:13] alfiemax: has joined #ruby
[05:38:58] dionysus69: has joined #ruby
[05:39:35] haraoka: has joined #ruby
[05:43:47] darkhanb: has joined #ruby
[05:46:05] Ryzokuken: has joined #ruby
[05:47:06] karapetyan: has joined #ruby
[05:48:18] ramfjord: has joined #ruby
[05:51:39] sytherax_: has joined #ruby
[05:55:20] BTRE: has joined #ruby
[05:56:06] conta: has joined #ruby
[05:56:40] alex``: has joined #ruby
[05:58:28] aupadhye: has joined #ruby
[05:59:03] schleppel: has joined #ruby
[06:04:40] roshanavand: has joined #ruby
[06:07:44] sagax: has joined #ruby
[06:07:48] alfiemax: has joined #ruby
[06:12:29] Ryzokuken: has joined #ruby
[06:12:34] sauvin: has joined #ruby
[06:15:23] biberu: has joined #ruby
[06:18:22] jenrzzz: has joined #ruby
[06:27:29] skryking_: has joined #ruby
[06:34:55] Azure: has joined #ruby
[06:39:04] DeepIO: has joined #ruby
[06:41:13] alfiemax: has joined #ruby
[06:45:27] mtkd: has joined #ruby
[06:47:34] amar_: has joined #ruby
[06:55:13] tvw: has joined #ruby
[06:57:01] sidx64: has joined #ruby
[06:58:16] c0ncealed1: has joined #ruby
[06:58:51] phaul: has joined #ruby
[07:00:50] amar_: has joined #ruby
[07:02:11] alfiemax: has joined #ruby
[07:03:09] sidx64: has joined #ruby
[07:05:39] mikecmpbll: has joined #ruby
[07:06:22] cadillac_: has joined #ruby
[07:07:20] sidx64: has joined #ruby
[07:08:20] dionysus69: has joined #ruby
[07:09:47] Nussi: has joined #ruby
[07:13:06] DeepIO: has joined #ruby
[07:14:05] paul0: has joined #ruby
[07:15:22] suukim: has joined #ruby
[07:17:05] tAn: has joined #ruby
[07:23:43] sidx64: has joined #ruby
[07:25:43] conta: has joined #ruby
[07:26:09] clemens3: has joined #ruby
[07:26:39] dinfuehr: has joined #ruby
[07:28:00] aufi: has joined #ruby
[07:28:48] amar: has joined #ruby
[07:30:11] contradictioned: has joined #ruby
[07:30:33] Mia: has joined #ruby
[07:33:24] schneider: has joined #ruby
[07:33:33] bga57: has joined #ruby
[07:39:20] DeepIO: has joined #ruby
[07:39:21] claudiuinberlin: has joined #ruby
[07:44:03] Ryzokuken: has joined #ruby
[07:44:05] amar: has joined #ruby
[07:44:23] amar: has joined #ruby
[07:48:09] arekushi: has joined #ruby
[07:48:12] fsmauri21: has joined #ruby
[07:48:18] ramfjord: has joined #ruby
[07:50:05] marr: has joined #ruby
[07:50:23] Mia: has joined #ruby
[07:50:23] Mia: has joined #ruby
[07:55:58] alfiemax: has joined #ruby
[07:56:57] DoubleMalt: has joined #ruby
[07:57:11] mikecmpb_: has joined #ruby
[07:57:28] mlkkk: has joined #ruby
[07:57:38] Silthias1: has joined #ruby
[07:58:11] burgestrand: has joined #ruby
[08:03:06] samosaphile: has joined #ruby
[08:08:21] venmx: has joined #ruby
[08:15:52] ur5us: has joined #ruby
[08:18:02] schneider: has joined #ruby
[08:19:11] conta1: has joined #ruby
[08:23:04] amar_: has joined #ruby
[08:24:19] amar_: has joined #ruby
[08:26:33] haraoka: has joined #ruby
[08:35:26] guille-moe: has joined #ruby
[08:35:50] jottr: has joined #ruby
[08:36:33] karapetyan: has joined #ruby
[08:37:43] conta: has joined #ruby
[08:50:30] mtkd: has joined #ruby
[08:50:53] schneider: has joined #ruby
[08:52:08] tomeaton17: has joined #ruby
[08:52:33] tomeaton17: I need to install ruby 2.0.0 onto lots of raspberry pi zeros. Is there a way I can do this without having to compile it on every device? takes a long time
[09:05:40] sytherax_: has joined #ruby
[09:07:50] venmx: has joined #ruby
[09:09:42] arquebus: has joined #ruby
[09:09:47] yohji: has joined #ruby
[09:14:46] clemens3: configure and compile/make on one machine, archive everything, and unzip, and then "make install" on each machine
[09:14:47] RyanMcCoskrie: has joined #ruby
[09:15:24] lxsameer: has joined #ruby
[09:15:57] tomeaton17: clemens3: Yeah seems like the way to go. Thanks
[09:25:13] ipe: has joined #ruby
[09:26:51] beefjoe70: has joined #ruby
[09:29:59] amar_: has joined #ruby
[09:30:23] karapetyan: has joined #ruby
[09:32:38] Silthias1: has left #ruby: ()
[09:37:05] plexigras: has joined #ruby
[09:37:09] beefjoe70: where can I find a ruby script that captures the stdout ?
[09:40:49] sytherax_: has joined #ruby
[09:40:55] catbusters: has joined #ruby
[09:41:21] Tempesta: has joined #ruby
[09:44:24] sytherax_: has joined #ruby
[09:44:53] fercell: has joined #ruby
[09:46:22] rivalomega: has joined #ruby
[09:48:58] ferr_: has joined #ruby
[09:49:06] NL3limin4t0r: has joined #ruby
[09:49:34] alfiemax: has joined #ruby
[09:49:49] ferr_: has joined #ruby
[09:50:28] ferr_: has joined #ruby
[09:57:26] clemens3: assign a new variable with $stdout, assignt $stdout with StringIO.new
[09:58:00] clemens3: do your thing, later collect the new output with $stdout.string, and reassign the the original state when done
[09:58:50] clemens3: but google might help..
[09:59:57] chouhoulis: has joined #ruby
[10:01:57] alfiemax: has joined #ruby
[10:05:08] arne: has joined #ruby
[10:05:13] dminuoso: Dont. Monkey patch. Global. Variables.
[10:05:44] mjolnird: has joined #ruby
[10:05:46] arne: wouldn't it be cool to have a magic variable inside an if true block that has the result of the rexpressio
[10:06:33] dminuoso: clemens3: Honestly the second you want this, stop pumping things into stdout.
[10:06:59] dminuoso: You can simply do `yourHandle.puts ...` instead of blindly using Kernel#puts
[10:07:11] arne: dminuoso: why not :(
[10:13:29] venmx: has joined #ruby
[10:20:29] apeiros: has joined #ruby
[10:20:48] amar_: has joined #ruby
[10:21:04] conta: has joined #ruby
[10:21:25] mtkd: has joined #ruby
[10:23:11] mikecmpbll: has joined #ruby
[10:29:20] contradictioned: has joined #ruby
[10:34:26] ElFerna: has joined #ruby
[10:34:39] clemens3: dminuoso: you anser beefjoe70
[10:38:06] beefjoe70: well I'm trying to create a script which returns the result of the code to the console
[10:38:14] beefjoe70: so like ruby test.rb 1+1
[10:38:19] beefjoe70: would return 2 to the console
[10:38:39] beefjoe70: `ruby test.rb 1+1`
[10:40:48] AJA4350: has joined #ruby
[10:42:46] clemens3: beefjoe70: ruby -e "put 2 + 2"
[10:42:57] clemens3: puts, damnit:)!
[10:44:35] beefjoe70: yea but I wanna have that in a script, so if the given code argument returns an error I'd get that too
[10:45:15] roshanavand: has joined #ruby
[10:46:35] karapetyan: has joined #ruby
[10:47:52] conta: has joined #ruby
[10:48:38] cschneid: has joined #ruby
[10:52:03] conta: has joined #ruby
[10:53:26] sytherax_: has joined #ruby
[10:54:23] clemens3: and the problem is?
[10:59:50] beefjoe70: clemens3 this is what I have https://hastebin.com/puzilasida.rb
[11:00:16] beefjoe70: not sure if it's correct, but I'm not even able to pass an argument on the command line :O
[11:01:45] Charliebr73: has joined #ruby
[11:06:05] contradictioned: has joined #ruby
[11:08:16] dionysus69: has joined #ruby
[11:08:33] DeepIO: has joined #ruby
[11:10:43] paul0: beefjoe70: Maybe the safest way to do what you are trying (so without overriding global variables) would be to create a tmp-file and redirect stdout and stderr to it. Then output that and default stdout and stderr again.
[11:11:02] alfiemax_: has joined #ruby
[11:12:15] karapetyan: has joined #ruby
[11:12:33] Mia: has joined #ruby
[11:13:37] paul0: So basically craete some tmp-file and use IO#reopen (stderr.reopen(tmpfile); stdout.reopen(tmpfile)) to really capture all of it while not being too intrusive.
[11:13:52] clemens3: beefjoe70: and what's this code example has to do with arguments on the command line..
[11:14:48] guille-moe: has joined #ruby
[11:15:58] clemens3: btw, hastebin doesn't work with a text browser
[11:17:03] beefjoe70: what do you mean
[11:17:04] paul0: beefjoe70: And for the input, lookup the ARGF constant. I think its better suited for your use case than stdin.
[11:17:31] paul0: (it basically acts like a file for the stdin input stream)
[11:17:59] clemens3: beefjoe70: you said you are not even able to pass an argument on the command line, I don't see the relation to your hastbin code example
[11:18:22] jenrzzz: has joined #ruby
[11:18:22] jenrzzz: has joined #ruby
[11:18:41] paul0: clemens3 I think thats just what he wants to do with the code once hes got it from the cmd line.
[11:19:28] paul0: with ARGF I think it would just be `Object.instance_eval ARGF.read`
[11:20:32] beefjoe70: yes exactly paul_
[11:21:40] karapetyan: has joined #ruby
[11:25:27] paul0: And Im completely wrong about ARGF by the way. It Just replaces file-names in ARGV with their respective contents :/ So I guess STDIN will have to do.
[11:26:15] clemens3: paul_: you meant ARGV..
[11:27:32] nowhere_man: has joined #ruby
[11:27:44] apeiros: paul_: ARGF is additionally to the files also stdin
[11:29:51] beefjoe70: though I'd rather do it without a tmp file
[11:30:14] beefjoe70: I think eval is good
[11:30:34] beefjoe70: I already wrote the script in another language and it works so I'm trying to convert it
[11:30:47] paul0: As far as I can see ARGF takes ARGV and treats the args as file names. ARGF.read then concatenates all of them. ARGV is just an array of the args (whitespace seperated I think).
[11:31:23] beefjoe70: this works fine with elixir https://pastebin.com/XGqMW4Gj
[11:31:23] ruby[bot]: beefjoe70: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[11:31:30] paul0: so "echo "puts ARGF.read" > argf.rb && ruby argf.rb argf.rb" returns "puts ARGF.read"
[11:33:43] beefjoe70: elixir and ruby seem similar that's why I'm trying to convert the code which works instead of writing from scratch in ruby
[11:37:03] conta: has joined #ruby
[11:38:13] ur5us: has joined #ruby
[11:39:11] dionysus69: has joined #ruby
[11:39:12] Cavallari: has joined #ruby
[11:40:15] ldnunes: has joined #ruby
[11:41:38] karapetyan: has joined #ruby
[11:43:08] aufi: has joined #ruby
[11:46:47] beefjoe70: hmm `ruby worker.rb '1+1'` doesn't return anything..
[11:47:01] beefjoe70: https://hastebin.com/ocakixuyoj.rb
[11:47:13] beefjoe70: using eval()
[11:48:09] ramfjord: has joined #ruby
[11:48:39] TinkerT: has joined #ruby
[11:49:03] ciscam: has joined #ruby
[11:50:22] beefjoe70: this https://hastebin.com/qifajiwoge.rb
[11:50:52] apeiros: beefjoe70: worker.rb only contains that code?
[11:53:15] getxsick: has joined #ruby
[11:54:30] getxsick: where can i read about behaviour of redifining class in the same file? i notices in pry/irb/ruby that once I redefine class it behaves like inheritance (not overridden methods are available from the old defininion!)
[11:55:25] apeiros: beefjoe70: well, then no wonder. that file only contains a class definition. you never actually invoke Capture.capture.
[11:55:46] Ryzokuken: has joined #ruby
[11:55:50] apeiros: getxsick: redefining a class does not work like inheritance.
[11:56:20] beefjoe70: apeiros then I get `wrong number of arguments (given 0, expected 1) (ArgumentError)`
[11:56:30] apeiros: getxsick: classes and modules in ruby are open. that means you can reopen them. it does not drop or replace the existing definition. you can run additional code in the class body to e.g. add more methods or explicitly remove some or whatever
[11:56:56] apeiros: beefjoe70: and why does that surprise you?
[11:57:08] beefjoe70: because I am passing an rgument
[11:57:22] beefjoe70: ruby worker.rb '1+1'
[11:57:28] apeiros: that's not the same
[11:57:39] getxsick: apeiros: yeah, it behaves like that. anyway, so how can i redefine class in Pry? it's pretty common case I believe. i can only restart interpreter?
[11:57:45] beefjoe70: how would I pass it then
[11:57:54] apeiros: Capture.capture is *one method* in your code. ruby will not just send arguments passed to the script to every method you invoke.
[11:58:16] apeiros: ARGV is an array which contains all arguments passed to your script.
[11:58:35] apeiros: getxsick: redefine as in "start over"?
[11:59:16] apeiros: you can't really. you can assign a new class object to the constant. but anything referencing the old class still will.
[11:59:26] apeiros: but most often it's sufficient to just redefine the methods you want
[11:59:34] paul0: getxsick You kann use `remove_const` and then redefine
[11:59:45] paul0: https://ruby-doc.org/core-2.5.1/Module.html#method-i-remove_const
[12:00:10] beefjoe70: `Capture.capture('1+1')` returns the expected result but with an error
[12:00:19] beefjoe70: `undefined local variable or method `result' for Capture:Class (NameError)
[12:00:19] beefjoe70: Did you mean? @result`
[12:00:54] getxsick: paul_: remove_const means i have to call it for each method?
[12:01:19] paul0: No for a class. The class will be gone then ( I guess, never used it myself).
[12:01:38] apeiros: beefjoe70: is there a question in that?
[12:01:49] VladGh: has joined #ruby
[12:01:55] beefjoe70: was just sharing what I'm going through
[12:02:09] apeiros: paul_: only the constant is gone. class being an object only will be gone if nothing references it anymore, like I said.
[12:02:36] alfiemax: has joined #ruby
[12:04:07] getxsick: paul_: no method `remove_const` for a class
[12:04:55] paul0: getxsick Yeah I mistook it for `Module#remove_const`. I thought there was a way to undefine a class though...
[12:05:52] beefjoe70: apeiros doing `Capture.capture(code)` says undefined variable, why's that ?
[12:06:12] apeiros: >> class Foo; end; Object.send(:remove_const, :Foo); Foo # as said, constant *can* be removed
[12:06:13] ruby[bot]: apeiros: # => uninitialized constant Foo (NameError) ...check link for more (https://eval.in/1008132)
[12:06:23] beefjoe70: doing Capture.capture('1+1') works fine though
[12:06:49] apeiros: >> class Foo; end; some_foo_instance = Foo.new; Object.send(:remove_const, :Foo); some_foo_instance.class # however, the *class* is still there, it just can't be accessed through the constant
[12:06:50] ruby[bot]: apeiros: # => Foo (https://eval.in/1008133)
[12:07:14] apeiros: paul_, getxsick: see the above two code examples. I hope those help you to understand how constants & classes are related.
[12:08:06] apeiros: beefjoe70: it usually says undefined variable because you have not defined a variable of that name. I assume it says that about "code"? why do you think that variable should exist there? what should be its value? where did you assign that value to it?
[12:09:25] paul0: apeiros thanks thats a good example :)
[12:09:37] alfiemax: has joined #ruby
[12:09:56] getxsick: apeiros: thx
[12:10:52] tbuehlmann: apeiros on fire
[12:11:21] sytherax_: has joined #ruby
[12:11:48] beefjoe70: I want it to be the argument, as in the code I pass into the class
[12:12:05] synthroid: has joined #ruby
[12:12:07] beefjoe70: and I have above `def self.capture(code)`
[12:13:10] apeiros: `def self.capture(code)` is for the method side of things, not for the calling side.
[12:13:39] beefjoe70: hmm how do I call the method then ?
[12:13:46] beefjoe70: I can pass arguments to it, it works
[12:13:55] beefjoe70: just not sure how to have that argument as a variable
[12:14:03] apeiros: it means that if you call the method `capture` with an argument, for the piece of code that makes up your method, that argument is assigned to `code`. that is unrelated to code outside the method.
[12:14:37] apeiros: it will work fine with a variable as an argument. but that variable must exist. they don't appear from thin air ;-)
[12:14:48] GodFather: has joined #ruby
[12:14:57] apeiros: i.e. `code = '1+1'; Capture.capture(code)` will work too.
[12:15:27] beefjoe70: yea, but I want code to be whatever I pass from the console
[12:15:43] beefjoe70: ruby script.rb code
[12:16:33] RougeR: has joined #ruby
[12:16:34] RougeR: has joined #ruby
[12:16:38] apeiros: yes. and ARGV contains those values.
[12:17:34] duderonomy: has joined #ruby
[12:21:10] conta: has joined #ruby
[12:21:45] karapetyan: has joined #ruby
[12:21:57] beefjoe70: weird, I keep getting `["worker.rb:9:in `eval'", "worker.rb:9:in `capture'", "worker.rb:22:in `<main>'"]`
[12:22:08] beefjoe70: doesn't matter what's the argument
[12:22:12] beefjoe70: I have code = argv
[12:23:32] apeiros: ok, please be precise. ARGV != argv.
[12:24:02] apeiros: note that ARGV is an array, it's not a string
[12:24:16] apeiros: each element in the array is one argument
[12:24:53] beefjoe70: now I used ARGV[0]
[12:25:03] apeiros: you're welcome
[12:26:17] sphenxes: has joined #ruby
[12:27:03] apeiros: beefjoe70: note: you should always reassign $stderr in your code. otherwise you'll miss it if the code emits something on stderr.
[12:27:40] apeiros: and plain puts will write to stdout anyway, not to stderr. so it's pointless in the rescue.
[12:28:13] beefjoe70: $stdout, $stderr = STDOUT, STDERR ?
[12:28:19] beefjoe70: to reassign
[12:28:48] apeiros: no, that part is fine. I mean before you run the code.
[12:29:03] alfiemax: has joined #ruby
[12:29:22] alfiemax: has joined #ruby
[12:29:54] beefjoe70: But the way I have it, it should write correctly to stderr and stdout correct ?
[12:30:09] beefjoe70: I mean I get the correct output on the console, but need to capture the result accordingly as well
[12:30:12] alfiemax_: has joined #ruby
[12:30:21] apeiros: define "correctly". as said, the part in the rescue now is pointless. and you'll miss it if the passed script emits something on $stderr.
[12:30:27] beefjoe70: gonna use the captured result with node
[12:30:48] beefjoe70: well when I do ruby script.rb "1+"
[12:30:53] beefjoe70: it returns an error
[12:31:00] conta1: has joined #ruby
[12:31:53] apeiros: take a close look on where it returns that error.
[12:32:10] beefjoe70: ["worker.rb:9:in `eval'", "worker.rb:9:in `capture'", "worker.rb:22:in `<main>'"]
[12:32:14] sytherax_: has joined #ruby
[12:32:26] beefjoe70: this isn't what I want
[12:32:30] apeiros: not what I meant
[12:32:39] apeiros: the backtrace itself is fine
[12:33:01] apeiros: though of course you can remove the running env from it. but that's not what I mean.
[12:33:08] apeiros: 14:27 apeiros: and plain puts will write to stdout anyway, not to stderr. so it's pointless in the rescue.
[12:33:42] beefjoe70: hmm but I need to know when there's an error and write it to stderr
[12:34:03] beefjoe70: I don't want it all in stdout
[12:34:22] apeiros: "and write it to stderr" - but you do not write it to stderr.
[12:34:30] apeiros: currently you write it to stdout
[12:35:02] beefjoe70: yea I got that, thanks for letting me know
[12:35:21] beefjoe70: how can I write to stderr ?
[12:35:28] apeiros: $stderr.puts
[12:35:52] beefjoe70: shouldn't I also do $stdout.puts to write to out ?
[12:36:44] apeiros: you can, but you don't have to
[12:36:52] guille-moe: has joined #ruby
[12:36:55] apeiros: plain `puts` is Kernel#puts, which is $stdout.puts
[12:37:20] beefjoe70: interesting
[12:37:24] beefjoe70: Looks good now
[12:37:39] beefjoe70: https://hastebin.com/epaqileven.rb
[12:37:46] beefjoe70: works good, with errors as well
[12:38:19] apeiros: and now try `ruby worker.rb '$stderr.puts "I go missing!"'`
[12:38:37] beefjoe70: `I go missing!`
[12:39:03] apeiros: but not in your return value…
[12:39:21] beefjoe70: I get I go missing!
[12:39:30] apeiros: on your screen, yes
[12:39:46] shinnya: has joined #ruby
[12:40:13] apeiros: huh, I see, your code has changed…
[12:40:14] beefjoe70: now doing ruby -e puts $stderr returns nothing
[12:40:35] apeiros: what happened to the `OpenStruct.new result: result, stdout: stdout.string, stderr: stderr.string` thing?
[12:41:16] karapetyan: has joined #ruby
[12:41:49] apeiros: so capture does not really have a return value. not sure how you want to use this thing then.
[12:42:09] beefjoe70: because it produced an error
[12:42:19] beefjoe70: undefined method `string' for nil:NilClass (NoMethodError)
[12:42:33] darix: has joined #ruby
[12:42:40] beefjoe70: https://hastebin.com/urivuzobow.rb
[12:43:31] jrafanie: has joined #ruby
[12:45:53] apeiros: beefjoe70: I'll ask as before - is there a question in that? :)
[12:46:31] beefjoe70: Why does it produce that error ?
[12:46:51] beefjoe70: btw doing ruby -e puts $stdout also returns nothing
[12:47:01] apeiros: what did you consider as likely reasons?
[12:47:43] beefjoe70: I'm not capturing the result
[12:47:48] beefjoe70: only printing it on the consol
[12:47:56] mtkd: has joined #ruby
[12:48:04] apeiros: (I might be replying slowly, working on the side…)
[12:48:26] apeiros: we'll look at your `ruby -e` later.
[12:48:51] apeiros: what do you understand about the error text "undefined method `string' for nil:NilClass (NoMethodError)"?
[12:48:59] apeiros: what does it tell you
[12:49:04] ramfjord: has joined #ruby
[12:49:05] beefjoe70: the string method isn't defined
[12:49:24] beefjoe70: I used it from this one here http://alphahydrae.com/2013/09/capturing-output-in-pure-ruby/
[12:49:32] beefjoe70: which explains how to capture stdout and stderr
[12:50:23] apeiros: ok. and on which objects do you try to call `.string`?
[12:50:47] apeiros: or maybe first: which line is the one that causes the problem?
[12:51:21] beefjoe70: so I guess both times on stdout and stderr
[12:51:49] beefjoe70: btw this is the code I'm working on https://hastebin.com/zoyukopaza.rb
[12:52:20] apeiros: ok. so either stdout.string, or stderr.string fail with that error.
[12:52:44] beefjoe70: hmm so I need to call each one in it's own code block ?
[12:52:53] apeiros: the "nil:NilClass" part gives you info about the object you try to call `.string` on. it means you call it on nil (which is an instance of NilClass)
[12:53:11] apeiros: no. you have to figure out which of the two is failing.
[12:53:22] apeiros: from which you can then draw further conclusions.
[12:53:27] beefjoe70: it's this stderr: stderr.string
[12:53:30] apeiros: and hopefully ultimately fix your bug.
[12:53:50] apeiros: ok. so the error tells you that stderr is nil, an instance of NilClass. what did you expect it to be?
[12:54:14] beefjoe70: the value of the error, if there's one
[12:54:58] apeiros: ok, let me ask differently. the object assigned to stderr, of which class should it be an instance?
[12:55:09] beefjoe70: https://hastebin.com/sehanahixi.rb
[12:55:22] beefjoe70: well at least no error now
[12:55:27] beefjoe70: not sure if it works properly
[12:55:40] apeiros: yeah, that's not a fix.
[12:55:58] apeiros: that's a "I stopped the pipe from leaking by closing the valve" :-p
[12:56:44] apeiros: I try to get you to learn to understand your errors and follow them back to their origin, and then actually fix it.
[12:57:13] beefjoe70: yea I appreciate it
[12:57:22] contradictioned: has joined #ruby
[12:58:29] beefjoe70: no idea how to proceed
[13:00:21] apeiros: proceed with my question :)
[13:00:28] apeiros: > ok, let me ask differently. the object assigned to stderr, of which class should it be an instance?
[13:00:32] sytherax_: has joined #ruby
[13:01:27] ogres: has joined #ruby
[13:02:32] apeiros: ok, in which line do you for the first time assign something to `stderr`?
[13:02:51] beefjoe70: stderr = StringIO.new
[13:02:54] beefjoe70: after the rescue
[13:03:19] apeiros: and after that line you expect `stderr.class` to be Capture?
[13:03:39] beefjoe70: oh right right
[13:03:44] beefjoe70: it's gotta be of the stringio class
[13:04:23] apeiros: ok. but in the line which raises, it is NilClass
[13:05:00] apeiros: so why is it nil, while expect it to be a StringIO instance? got an idea?
[13:05:47] apeiros: is the line `stderr = StringIO.new` always executed?
[13:05:58] apeiros: I mean, if you call Capture.capture
[13:06:09] beefjoe70: no not necessarily
[13:06:15] beefjoe70: if there's no error, then no
[13:06:26] apeiros: ok. so if there's no error, what value will `stderr` have?
[13:06:39] beefjoe70: the error message ?
[13:06:49] apeiros: what error message? there is no error…
[13:06:59] beefjoe70: oh no error
[13:07:50] apeiros: ok. so when there's no error, stderr will be nil, which in turn causes an exception because there's no nil.string. so that's your issue.
[13:08:53] apeiros: got an idea on how to solve that?
[13:09:06] beefjoe70: so what's wrong with the way I did it afterwards ? to only call .string when there's an error
[13:09:42] apeiros: the only "afterwards" I've seen was when you just commented out the entire OpenStruct line.
[13:10:18] beefjoe70: look line 19
[13:11:02] apeiros: oh. worse even. you create an object which you throw away :D
[13:11:13] apeiros: but yes, the stderr/stdout part would work.
[13:11:27] beefjoe70: the problem is that I'm not catching it, correct ?
[13:11:36] beefjoe70: because doing ruby -e doesn't return the stdout for example
[13:11:53] apeiros: you have to start distinguishing between "return" and "print"
[13:12:02] apeiros: those two are not the same and not interchangeable.
[13:12:48] apeiros: shell scripts don't return. they print stuff. usually on stdout/stderr.
[13:13:56] beefjoe70: so how do I return to stdout and stderr
[13:13:58] beefjoe70: not just print
[13:15:02] apeiros: in ruby, the last value of a method is returned. you can also explicitly use the return statement.
[13:15:23] apeiros: >> def foo; "hello"; "world"; end; foo
[13:15:24] ruby[bot]: apeiros: # => "world" (https://eval.in/1008187)
[13:15:31] apeiros: >> def foo; return "hello"; "world"; end; foo
[13:15:32] ruby[bot]: apeiros: # => "hello" (https://eval.in/1008188)
[13:25:15] bmurt: has joined #ruby
[13:26:01] samort7: has joined #ruby
[13:26:25] ByronJohnson: has joined #ruby
[13:26:58] sysfault: shell scripts return values which are stored in $?
[13:27:30] beefjoe70: now stderr returns nothing lol
[13:27:36] beefjoe70: require 'stringio'
[13:27:37] beefjoe70: require 'ostruct'
[13:27:37] beefjoe70: class Capture
[13:27:38] beefjoe70: def self.capture(code)
[13:27:39] beefjoe70: stdout = StringIO.new
[13:27:39] beefjoe70: $stdout = stdout
[13:27:40] beefjoe70: puts eval(code)
[13:27:41] beefjoe70: OpenStruct.new stdout: stdout.string
[13:27:41] beefjoe70: STDOUT.puts $stdout.string
[13:27:41] beefjoe70: rescue Exception => e
[13:27:42] beefjoe70: stderr = StringIO.new
[13:27:42] beefjoe70: $stderr = stderr
[13:27:43] beefjoe70: $stderr.puts
[13:27:43] beefjoe70: puts e.message
[13:27:44] beefjoe70: OpenStruct.new stderr: stderr.string
[13:27:45] beefjoe70: STDERR.puts $stderr.string
[13:28:15] beefjoe70: I get the correct stdout result printed, but not stderr when there's an error
[13:28:22] beefjoe70: even though I have puts e.message
[13:28:52] KeyJoo: has joined #ruby
[13:29:42] KeyJoo: has joined #ruby
[13:30:41] apparition: has joined #ruby
[13:31:29] brendan-: has joined #ruby
[13:33:59] sytherax_: has joined #ruby
[13:38:32] apeiros: beefjoe70: please paste >3 lines on gist (or another paste service)
[13:39:24] apeiros: $stderr.puts is just the method. you have to actually print something.
[13:39:57] apeiros: foo.bar(baz) # <-- call the method "bar" on the object referenced by "foo" and pass it one argument "baz"
[13:40:12] apeiros: that's 101 though and it might be a good idea you start reading a book to get those 101
[13:40:52] kapil___: has joined #ruby
[13:41:00] nowhere_man: has joined #ruby
[13:41:34] karapetyan: has joined #ruby
[13:41:39] ohcibi: has joined #ruby
[13:43:23] quobo: has joined #ruby
[13:43:45] beefjoe70: but I have puts e.message
[13:43:53] beefjoe70: which should print the error ?
[13:45:10] apeiros: to stdout, yes. and where does stdout go?
[13:46:00] apeiros: eh, since you named your lvar "stdout" let me be more precise:
[13:46:03] apeiros: to $stdout, yes. and where does stdout go?
[13:46:11] apeiros: whoops, premature enter :D
[13:46:15] apeiros: to $stdout, yes. and where does $stdout go? # final
[13:46:46] rivalomega: has joined #ruby
[13:52:44] apeiros: has joined #ruby
[13:53:18] pastorinni: has joined #ruby
[13:55:15] catbusters: has joined #ruby
[13:56:15] aufi: has joined #ruby
[13:57:27] conta2: has joined #ruby
[13:58:14] Rapture: has joined #ruby
[13:58:50] amelliaa: has joined #ruby
[14:00:30] Asher: has joined #ruby
[14:01:35] gnufied: has joined #ruby
[14:03:22] safetypin: has joined #ruby
[14:03:32] fsmauri21: Ok so in one of the exercises it has puts "Roosters #{100 - 25 * 3 % 4}"
[14:03:47] fsmauri21: After I ran the file, it gave me Roosters 97
[14:04:01] fsmauri21: My question is how is % used in that context?
[14:04:12] fsmauri21: I looked it up and got so many other answers..
[14:04:27] fsmauri21: Is it a remainder? Or does it work like an array?
[14:06:37] ohcibi: has joined #ruby
[14:06:40] pastorinni: has joined #ruby
[14:07:10] pastorinni: has joined #ruby
[14:07:30] banisterfiend: has joined #ruby
[14:07:58] canton7: it's remainder.
[14:08:27] canton7: 75 % 4 = 3, because 4 * 18 = 72, and 75 - 72 = 3
[14:08:50] karapetyan: has joined #ruby
[14:09:22] havenwood: FsMauri21: You can alternatively use the Integer#modulo method for the same effect.
[14:09:45] havenwood: >> 75.modulo(4) == 75 % 4
[14:09:46] ruby[bot]: havenwood: # => true (https://eval.in/1008230)
[14:10:32] havenwood: >> 75.divmod(4) == [75 / 4, 75 % 4]
[14:10:33] ruby[bot]: havenwood: # => true (https://eval.in/1008232)
[14:10:54] fsmauri21: Thats a neat bot.
[14:11:00] havenwood: ACTION bows
[14:11:36] sytherax_: has joined #ruby
[14:11:55] face: has joined #ruby
[14:12:09] havenwood: ACTION realizes he's not the bot.
[14:14:42] fsmauri21: Ah man, would have been a nice AI bot..
[14:14:45] torstein: has joined #ruby
[14:16:01] apeiros: FsMauri21: and how to look it up: figure out on what value it is invoked on (in this case on 25*3 == 75), figure out the class of that (75.class => Integer) and then use ri in your console: `ri Integer#%`
[14:16:26] apeiros: alternatively to ri, you can also use ruby-doc.org or another API doc website. just don't use google. that's a rather bad way to access api docs :)
[14:16:38] fsmauri21: I knew the math it was doing, but I wanted to be able to understand it in words.
[14:16:57] fsmauri21: Reading up on it, it has other uses and that was slightly confusing.
[14:17:01] torstein: I've got a bsearch question; is it possible to find the highest value less than x?
[14:17:16] havenwood: >> 75.method(:%).owner
[14:17:17] ruby[bot]: havenwood: # => Fixnum (https://eval.in/1008239)
[14:17:32] torstein: lowest value is trivial: Array.new(20) { rand 1000 }.sort.bsearch { |n| n > 250 }
[14:17:50] faces: has joined #ruby
[14:17:54] torstein: but how to find the highest value below 750?
[14:18:08] havenwood: Torstein: That'll often be a different value, not the lowest.
[14:18:26] fsmauri21: Thanks for the page link Apeiros.
[14:18:48] havenwood: Torstein: Try it a few times in irb or pry.
[14:18:59] havenwood: Torstein: Note the value changes.
[14:19:59] chouhoulis: has joined #ruby
[14:21:21] alfiemax: has joined #ruby
[14:21:29] torstein: yes, that is what I want. the lowest value above 250, naturally it will change with the random values.
[14:22:22] torstein: Array.new(20) { rand 1000 }.sort.tap { |a| puts a }.bsearch { |n| n > 250 } <--- you expect this not to return the lowest value above 250?
[14:22:45] torstein: tried it a few times in irb, looks to be working the way I expect
[14:22:57] havenwood: Torstein: Ah, I misunderstood what you were asking. Nvm!
[14:23:38] torstein: yeah, so I want to go from the other side, and find the _highest_ value _below_ 750
[14:24:06] havenwood: Torstein: You could reverse the sort.
[14:24:09] torstein: (without using reverse)
[14:24:27] dviola: has joined #ruby
[14:24:40] havenwood: Torstein: sort_by { |n| -n }.bsearch { |n| n < 250 }
[14:24:47] torstein: reverse is O(n)?
[14:24:51] havenwood: But yeah, reversing. ;-P
[14:25:17] havenwood: Torstein: You can do it when you sort, so you don't have to sort then reverse.
[14:25:45] jamiejackson: has joined #ruby
[14:25:45] torstein: how do you mean?
[14:26:09] havenwood: Torstein: You're sorting by n, but you can just sort by -n.
[14:26:18] havenwood: It'll end up in the reverse order.
[14:26:23] conta: has joined #ruby
[14:26:47] torstein: ok, let me backtrack
[14:26:54] torstein: I got a SortedSet
[14:27:09] torstein: and I want to get the elements in the range from X to Y
[14:29:09] torstein: Array.new(20) { rand 1000 }.to_set.get_range(250, 750) # Imagine we required 'set' and inherited from it so that we can implement get_range(min, max)
[14:29:36] karapetyan: has joined #ruby
[14:30:05] torstein: there has to be a way to get the highest value of the set below 750 in O(lg n), right?
[14:33:09] justizin: has joined #ruby
[14:41:03] Cavallari: has joined #ruby
[14:44:03] havenwood: Torstein: Do you want the range or the min and max value?
[14:44:42] havenwood: I guess you were only getting min and max to get at the range?
[14:46:22] torstein: yeah, I want the indexes of the min and max values within the range, so that I can do some_sorted_set.to_a.values_at(min..max)
[14:47:14] torstein: (min_index..max_index) would be better var names
[14:47:35] torstein: and the goal is to find both min_index and max_index in O(lg n)
[14:49:10] AJA4351: has joined #ruby
[14:50:51] havenwood: Torstein: bsearch is indeed fast
[14:51:25] havenwood: it's the most contorted code, by far
[14:51:57] grilix: has joined #ruby
[14:53:04] mtkd: has joined #ruby
[14:53:17] havenwood: Torstein: https://gist.github.com/havenwood/90523205648145918aee9e6799fdf7e3
[14:54:08] sytherax_: has joined #ruby
[14:54:43] havenwood: The difference gets bigger as the SortedSet grows.
[14:54:50] demio: has joined #ruby
[14:55:49] orbyt_: has joined #ruby
[14:56:48] arne: when i do eval "w = 3"
[14:56:52] torstein: hmm.. I suppose reversing will have to do for now
[14:56:58] arne: why don't i have eval inside the currenct scope?
[14:57:09] rivalomega: has joined #ruby
[14:58:25] havenwood: >> binding == binding
[14:58:26] ruby[bot]: havenwood: # => false (https://eval.in/1008268)
[14:58:26] torstein: try Kernel.eval "w = 3"
[14:58:58] arne: does binding always return a new binding?
[14:59:17] demio: has left #ruby: ()
[14:59:17] havenwood: >> this_binding = binding; this_binding.eval 'w = 3'; this_binding.eval 'w'
[14:59:18] ruby[bot]: havenwood: # => 3 (https://eval.in/1008270)
[14:59:30] arne: i see, thanks
[14:59:37] arne: i guess it does, except for <cases>
[14:59:43] oleo: has joined #ruby
[14:59:43] arne: like being inside a proc or something?
[15:00:28] Asher: has joined #ruby
[15:00:31] AJA4351: has joined #ruby
[15:00:35] havenwood: arne: eval takes a binding as a second arg
[15:00:55] rivalomega: has joined #ruby
[15:01:46] havenwood: >> this_binding = binding; eval 'w = 3', this_binding; this_binding.eval 'w'
[15:01:47] ruby[bot]: havenwood: # => 3 (https://eval.in/1008273)
[15:01:59] arne: ah, i even used this once
[15:02:06] arne: thanks alot
[15:02:09] havenwood: err, I mean:
[15:02:10] havenwood: >> this_binding = binding; eval 'w = 3', this_binding; eval 'w', this_binding
[15:02:11] arne: binding still confusing imho
[15:02:11] ruby[bot]: havenwood: # => 3 (https://eval.in/1008275)
[15:02:46] arne: is it Kernel#binding?
[15:02:48] arne: where can i read about it
[15:03:20] havenwood: arne: https://ruby-doc.org/core/Binding.html
[15:03:22] arne: so binding returns a copy of the current scope?
[15:03:29] arne: not the scope itself?
[15:03:41] arne: or rather a "child" of the scope?
[15:03:53] cschneid: has joined #ruby
[15:04:58] phaul: has joined #ruby
[15:04:59] havenwood: https://ruby-doc.org/core/Kernel.html#method-i-binding
[15:06:30] AJA4350: has joined #ruby
[15:06:44] havenwood: https://github.com/ruby/ruby/blob/730d257b5a6bc0808116d91dbbaae73344273781/vm.c#L918-L947
[15:08:05] coderphive: has joined #ruby
[15:08:43] marr: has joined #ruby
[15:09:04] cyberg: has joined #ruby
[15:09:08] sumobob: has joined #ruby
[15:09:15] arne: man i love ruby c code
[15:11:22] RougeR: does this look right?
[15:11:25] RougeR: @gyms = Gym.where({created_at: (Time.now - 48.hours)..Time.now, active: false)}
[15:11:48] RougeR: syntax error, unexpected ')', expecting '}'
[15:12:03] havenwood: RougeR: Nope!
[15:12:18] havenwood: RougeR: There are a couple issues.
[15:12:39] havenwood: RougeR: The most immediate is that the ) and } at the end are in the wrong order.
[15:13:09] arne: havenwood: but as far as i understand it creates a new binding and writes stuff to it, so it would be some sort of a copy?
[15:13:22] RougeR: havenwood: really?
[15:13:30] RougeR: its obvious not right i agree
[15:13:32] RougeR: i was following this
[15:13:33] RougeR: https://apidock.com/rails/ActiveRecord/QueryMethods/where
[15:13:42] RougeR: User.where({ name: "Joe", email: "joe@example.com" })
[15:14:20] havenwood: arne: I mean it's a new Binding object, so it's a thing in itself. It has references to the point of call from the scope where it was made.
[15:14:38] RougeR: havenwood: ah shit
[15:14:43] RougeR: at the end brackets
[15:15:09] RougeR: working now
[15:15:26] arne: havenwood: so a copy :D at that time
[15:15:55] havenwood: arne: Nothing is copied though, just a binding.
[15:16:46] havenwood: arne: Yeah, I see what you're saying.
[15:17:04] fsmauri21: Thanks again Havenwood. Adios.
[15:17:16] havenwood: Maybe copy isn't the best word. But yes.
[15:17:18] fsmauri21: has left #ruby: ("Leaving")
[15:17:21] havenwood: arne: I don't understand it well enough to explain it. ;-)
[15:18:00] arne: havenwood: okay, thanks alot
[15:21:41] pastorin_: has joined #ruby
[15:30:21] sytherax_: has joined #ruby
[15:31:12] ldnunes: has joined #ruby
[15:32:21] banisterfiend: has joined #ruby
[15:35:42] Zaab1t: has joined #ruby
[15:35:53] rivalomega: has joined #ruby
[15:39:22] pastorinni: has joined #ruby
[15:40:04] cagomez: has joined #ruby
[15:42:21] kmurphy4: has joined #ruby
[15:44:09] nielsk: has joined #ruby
[15:47:35] cagomez: has joined #ruby
[15:50:18] dionysus69: has joined #ruby
[15:56:02] apeiros: has joined #ruby
[15:57:32] jcarl43: has joined #ruby
[15:59:52] pastorinni: has joined #ruby
[16:01:44] npgm: has joined #ruby
[16:01:53] conta: has joined #ruby
[16:07:34] karapetyan: has joined #ruby
[16:12:41] Xeago: has joined #ruby
[16:13:07] amar_: has joined #ruby
[16:14:17] thapakazi: has joined #ruby
[16:14:26] thapakazi_: has joined #ruby
[16:16:44] orbyt_: has joined #ruby
[16:16:53] KeyJoo: has joined #ruby
[16:17:25] [Butch]: has joined #ruby
[16:17:47] apeiros: has joined #ruby
[16:17:50] bmurt: has joined #ruby
[16:21:21] shinnya: has joined #ruby
[16:23:51] cthulchu: has joined #ruby
[16:26:21] darkhanb: has joined #ruby
[16:27:39] [Butch]: has joined #ruby
[16:28:40] apeiros: has joined #ruby
[16:31:19] guille-moe: has joined #ruby
[16:31:21] jenrzzz: has joined #ruby
[16:31:22] jenrzzz: has joined #ruby
[16:37:56] tAn: has joined #ruby
[16:38:26] grilix: has joined #ruby
[16:38:31] \void: has joined #ruby
[16:38:58] Mike11: has joined #ruby
[16:39:15] clemens3: has joined #ruby
[16:39:41] suukim: has joined #ruby
[16:39:42] sumobob: has joined #ruby
[16:41:45] guacamole: has joined #ruby
[16:41:45] guacamole: has joined #ruby
[16:44:36] guacamole: has joined #ruby
[16:44:36] guacamole: has joined #ruby
[16:48:44] nowhere_man: has joined #ruby
[16:50:43] sanscoeur: has joined #ruby
[16:50:54] cagomez: is it possible to splat a hash without passing it as a param? ie just `*hash.values` returned from a method
[16:51:20] dminuoso: cagomez: what does "splat a hash" mean for you
[16:51:22] sumobob: has joined #ruby
[16:51:26] nitric: has joined #ruby
[16:51:38] sanscoeur: has joined #ruby
[16:52:25] dminuoso: cagomez: hash.values returns an array.
[16:52:43] amar_: has joined #ruby
[16:53:07] cagomez: ah ok, got it
[16:57:04] Silox|: has joined #ruby
[16:57:36] pilne: has joined #ruby
[16:57:42] mtkd: has joined #ruby
[17:02:02] AJA4350: has joined #ruby
[17:02:32] dtzuzu: has joined #ruby
[17:04:53] guacamole: has joined #ruby
[17:05:25] mlkkk: has joined #ruby
[17:05:39] AgentVenom: has joined #ruby
[17:06:33] Puffball: has joined #ruby
[17:07:11] ruby[bot]: -bb $a:jongley$#ruby-banned jongley!*@*$#ruby-banned
[17:08:54] pastorinni: has joined #ruby
[17:09:07] nowhere_man: has joined #ruby
[17:16:24] ogres: has joined #ruby
[17:22:42] sudorobo: has joined #ruby
[17:22:42] sudorobo: has joined #ruby
[17:23:49] conta: has joined #ruby
[17:24:03] SirFunk: has joined #ruby
[17:26:23] guacamole: has joined #ruby
[17:26:24] guacamole: has joined #ruby
[17:29:20] brendan-: has joined #ruby
[17:30:47] chouhoul_: has joined #ruby
[17:32:27] jenrzzz: has joined #ruby
[17:33:08] synthroid: has joined #ruby
[17:33:45] chouhoul_: has joined #ruby
[17:35:25] SirFunk: has joined #ruby
[17:43:10] conta: has joined #ruby
[17:45:48] mtkd: has joined #ruby
[17:47:16] GodFather: has joined #ruby
[17:48:16] jrafanie: has joined #ruby
[17:49:01] RougeR: heya, i need some help with my join table
[17:49:22] RougeR: ive not really used one before. im pretty sure the relations are correct
[17:49:42] RougeR: but im confused on how to start saving relations
[17:50:12] paul0: has joined #ruby
[17:50:17] RougeR: x-posting to #RoR
[17:55:24] banisterfiend: has joined #ruby
[18:00:52] Axy: has joined #ruby
[18:00:52] Axy: has joined #ruby
[18:01:48] Asher: has joined #ruby
[18:02:38] matled-: has joined #ruby
[18:03:17] dviola: has joined #ruby
[18:03:27] nitric_: has joined #ruby
[18:03:59] jrich523: has joined #ruby
[18:04:40] nayena: has joined #ruby
[18:06:23] amar: has joined #ruby
[18:08:48] Mia: has joined #ruby
[18:12:42] Axy: has joined #ruby
[18:12:42] Axy: has joined #ruby
[18:16:02] Mia: has joined #ruby
[18:21:33] ramfjord: has joined #ruby
[18:26:42] conta: has joined #ruby
[18:27:03] phaul: has joined #ruby
[18:28:37] cagomez: why can't I call `current_time_from_proper_timezone` on a ActiveRecord class? https://github.com/rails/rails/blob/master/activerecord/lib/active_record/timestamp.rb#L60
[18:29:10] cagomez: but if I initialize a model, I can do `model.send(:current_time_from_proper_timezone)`
[18:30:47] bmurt: has joined #ruby
[18:31:55] Asher: has joined #ruby
[18:32:41] guille-moe: has joined #ruby
[18:34:54] Cavallari: has joined #ruby
[18:35:12] mtkd: has joined #ruby
[18:42:23] t0xik: has joined #ruby
[18:49:47] Axy: has joined #ruby
[18:51:18] coderphive: has joined #ruby
[18:59:12] chouhoulis: has joined #ruby
[19:03:35] alfiemax: has joined #ruby
[19:07:08] rivalomega: has joined #ruby
[19:07:57] jarnalyrkar: has joined #ruby
[19:08:05] cadillac_: has joined #ruby
[19:08:13] rivalomega: has joined #ruby
[19:10:29] rivalomega: has joined #ruby
[19:11:14] mjolnird: has joined #ruby
[19:14:37] SuperL4g: has joined #ruby
[19:16:01] bmurt: has joined #ruby
[19:16:54] karapetyan: has joined #ruby
[19:23:04] quobo: has joined #ruby
[19:24:08] mikecmpbll: has joined #ruby
[19:26:14] jmaister: has joined #ruby
[19:28:12] jmaister: Hi! I'm trying to get r18n to work, but have little success. I have this very simple program https://pastebin.com/iSLrv8nf and a translation file https://pastebin.com/eRuxU8Vn in the correct place, but it doesn't seem to find my translation
[19:28:13] ruby[bot]: jmaister: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[19:29:11] jmaister: I tried in irb, and it gives me this https://gist.github.com/jurgemaister/977832fbe6565671c735773b39dfc130 @untranslated_path="file.add"
[19:29:44] _aeris_: has joined #ruby
[19:32:13] sudorobo: has joined #ruby
[19:32:13] sudorobo: has joined #ruby
[19:33:13] alfiemax: has joined #ruby
[19:36:01] BH23: has joined #ruby
[19:36:50] cagomez: has joined #ruby
[19:38:31] jmaister: never mind, I called my yaml file .yaml and not .yml. I'm stupid
[19:45:41] banisterfiend: has joined #ruby
[19:48:20] GodFather: has joined #ruby
[19:49:20] rivalomega: has joined #ruby
[19:49:55] rivalomega: has joined #ruby
[19:52:36] herbmillerjr: has joined #ruby
[19:58:16] alfiemax: has joined #ruby
[20:00:22] darkhanb: has joined #ruby
[20:02:12] eckhardt: has joined #ruby
[20:05:37] jenrzzz_: has joined #ruby
[20:07:03] banisterfiend: has joined #ruby
[20:08:14] cagomez: has joined #ruby
[20:08:27] torstein: has joined #ruby
[20:10:11] ruby[bot]: -b squishyj!*@*$#ruby-banned
[20:11:18] joro_: has joined #ruby
[20:13:21] jmaister: has left #ruby: ()
[20:13:24] bmurt: has joined #ruby
[20:19:40] bmurt: has joined #ruby
[20:25:02] torstein: havenwood: this is absurd https://gist.github.com/havenwood/90523205648145918aee9e6799fdf7e3#gistcomment-2597465
[20:29:46] sinduck: has joined #ruby
[20:31:09] alfiemax: has joined #ruby
[20:32:19] nayena: has joined #ruby
[20:32:24] mikecmpbll: has joined #ruby
[20:50:30] Dbugger: has joined #ruby
[20:51:48] nkh^: has joined #ruby
[20:57:01] cagomez: has joined #ruby
[20:58:58] duderonomy: has joined #ruby
[21:04:50] rivalomega: has joined #ruby
[21:06:39] vulgrin: has joined #ruby
[21:07:42] Mia: has joined #ruby
[21:07:42] Mia: has joined #ruby
[21:08:58] vulgrin: has joined #ruby
[21:12:20] havenwood: has joined #ruby
[21:12:20] havenwood: has joined #ruby
[21:13:25] rivalomega: has joined #ruby
[21:15:25] rivalome_: has joined #ruby
[21:16:09] rivalomega: has joined #ruby
[21:18:29] tdy: has joined #ruby
[21:20:22] jrafanie: has joined #ruby
[21:21:12] jrafanie: has joined #ruby
[21:24:13] chouhoulis: has joined #ruby
[21:28:37] jenrzzz: has joined #ruby
[21:28:48] amelliaa: has joined #ruby
[21:32:09] kmurphy4: has joined #ruby
[21:32:22] GodFather: has joined #ruby
[21:32:38] amar: has joined #ruby
[21:33:21] plexigras: has joined #ruby
[21:38:56] _aeris_: has joined #ruby
[21:39:57] alfiemax: has joined #ruby
[21:51:30] regedit: has joined #ruby
[22:02:19] eckhardt: has joined #ruby
[22:04:14] XB23: has joined #ruby
[22:06:38] cagomez: has joined #ruby
[22:08:38] nkh^: has joined #ruby
[22:10:13] Mia: has joined #ruby
[22:10:14] Mia: has joined #ruby
[22:12:10] orbyt_: has joined #ruby
[22:12:13] jenrzzz: has joined #ruby
[22:12:17] alfiemax: has joined #ruby
[22:16:58] mlkkk: has joined #ruby
[22:17:24] ramfjord: has joined #ruby
[22:17:39] RyanMcCoskrie: has joined #ruby
[22:25:49] jenrzzz: has joined #ruby
[22:25:56] RyanMcCoskrie: has joined #ruby
[22:35:30] alfiemax: has joined #ruby
[22:36:13] nkh^: has joined #ruby
[22:36:34] raul782: has joined #ruby
[22:37:40] dviola: has joined #ruby
[22:40:33] Axy: has joined #ruby
[22:40:33] Axy: has joined #ruby
[22:45:26] mlkkk: has joined #ruby
[22:46:24] ramfjord: has joined #ruby
[22:49:24] jenrzzz: has joined #ruby
[22:51:41] venmx: has joined #ruby
[22:52:21] ramfjord: has joined #ruby
[22:52:57] pastorinni: has joined #ruby
[22:59:50] Radar: Brainstrust: If I have an array like [1,2,2,3,4] and I want to take away [2,4], but then end up with [1,2,3], what's the trick?
[23:02:33] eam: do you always want to remove the first duplicate? I think I'd have to write a method
[23:03:42] Radar: I want something like [1,2,2,3,4] - [2,4], but without it removing both 2s.
[23:03:51] Radar: > [1,2,2,3,4] - [2,4],
[23:03:55] Radar: >> [1,2,2,3,4] - [2,4]
[23:03:56] ruby[bot]: Radar: # => [1, 3] (https://eval.in/1008428)
[23:04:48] moei: has joined #ruby
[23:12:07] stairmast0r: has joined #ruby
[23:12:10] Vasa: has joined #ruby
[23:15:18] ramfjord: has joined #ruby
[23:16:49] baweaver: Radar: sets potentially with a pop action.
[23:18:53] eam: I think I'd iterate the first array and for each item iterate the second array, removing from both on match
[23:19:28] Radar: One of the people here came up with: second.each { |t| first.delete_at(first.index(t)) }
[23:19:44] Radar: I suggested: (a & b).each { |t| a.delete_at(a.index(t)) }, just so you're not needlessly iterating through elements that don't exist in a.
[23:20:03] Radar: But I am not sure if that is worth any timesavings or if it's just fancy for the sake of fancy.
[23:20:50] baweaver: >> def delete_first(array, set) ns = Set.new(set); array.reject { |v| ns.include?(v).tap { ns.delete(v) }} end; delete_first([1,2,2,3,4], [2,4])
[23:20:51] ruby[bot]: baweaver: # => uninitialized constant Set (NameError) ...check link for more (https://eval.in/1008429)
[23:21:12] baweaver: >> require 'set'; def delete_first(array, set) ns = Set.new(set); array.reject { |v| ns.include?(v).tap { ns.delete(v) }} end; delete_first([1,2,2,3,4], [2,4])
[23:21:13] ruby[bot]: baweaver: # => [1, 2, 3] (https://eval.in/1008430)
[23:21:42] gix: has joined #ruby
[23:21:46] ramfjord: has joined #ruby
[23:22:12] Radar: Good to know that I'm not overlooking a potential built-in method to do this.
[23:22:40] baweaver: It deals with two distinct collections, so not really one out there
[23:22:59] jenrzzz: has joined #ruby
[23:22:59] jenrzzz: has joined #ruby
[23:23:02] BTRE: has joined #ruby
[23:23:58] vulgrin: has joined #ruby
[23:25:51] baweaver: If they're both sorted though you could potentially make it faster.
[23:26:25] baweaver: then it's a matter of moving an index pointer instead of mutating a deletion set
[23:29:07] baweaver: >> def sorted_first_reject(as, ns) p=0; as.reject { |a| ns[p] == a && p += 1 } end; sorted_first_reject([1,2,2,3,4], [2,4])
[23:29:09] ruby[bot]: baweaver: # => [1, 2, 3] (https://eval.in/1008433)
[23:31:35] eam: aren't those going to barf when there are multiple repeats in the second array?
[23:31:55] eam: gotta iron out the semantics -- is it only ever removing the first instance and is the second array unique?
[23:33:55] shinnya: has joined #ruby
[23:46:33] jamesaxl: has joined #ruby
[23:53:22] kmurphy4: has joined #ruby
[23:53:49] alfiemax: has joined #ruby
[23:53:58] nicesignal: has joined #ruby
[23:55:31] pabs: has joined #ruby