#ruby - 22 January 2018
« Back 1 day Forward 1 day »
[01:09:20] leitz: There are various "net" packages in stdlib; is there one that's very minimal to create your own service?
[11:04:02] burgestrand: leitz case uses `===` for matching, with the subject on the right-hand-side, e.g. `case x; when a; end` will compare `a === x`
[11:07:47] leitz: So far "when >= 60" didn't work. I'm assuming operator error, it's just too early into my coffee.
[11:08:51] yohji: leitz: yeah. as Burgestrand said, it is a right-hand-side operator. you can use: when n >= 60 ...
[11:10:19] burgestrand: I guess magic is too strong a word, but I wouldn't call it common knowledge that case uses `===`, even though it probably should be :d
[11:20:01] leitz: Hmm... let me think on this. I think i know the answer but it's not speaking up. Trying to write a test in the same directory as the code but it's not loading.
[11:21:16] leitz: To "require" something, does it have to be a class? Can it just be a library with methods?
[11:30:31] leitz: Burgestrand, both files are in the same directory. https://gist.github.com/LeamHall/677c142bd5c9428a7a63e8d6fd79b77b
[11:31:44] burgestrand: leitz if you don't make the path explicitly relative or absolute, ruby will search in an array of directories listed in `$LOAD_PATH` for the file you attempt to require, and if it can't find it will give you the error you see there
[11:42:11] leitz: Okay, tests pass and code works but needs work. Time to get ready for paying work. See you all later.
[14:36:45] bijan_: Hi, anyone knows how I can build up a nested hash in ruby and add arbitrary nested keys in a loop? the end result shall be a json with nested elements
[16:10:24] havenwood: za1b1tsu: Yeah, it's handy from time to time. I usually use &public_method unless it's private - even though it's more verbose.
[16:11:49] ruby[bot]: havenwood: # => method `puts' for class `#<Class:#<Object:0x41819340>>' is private (NameError) ...check link for more (https://eval.in/940079)
[16:53:12] FrostCandy: Prgramming is hard, when I grow up I want to be a non-essential governmental worker. :)
[16:53:39] apeiros: FrostCandy: that depends on whatever you use to connect to your db. but usually, database drivers translate NULL to nil
[16:55:05] apeiros: but again, depends on your db & db driver. oracle f.ex. usually doesn't store empty strings but instead turns it to NULL (which in turn is usually represented as nil in ruby)
[16:55:07] FrostCandy: it shouldn't, so to check for nil or empty do i need to check 2 things or is there a idomatic way of checking this in ruby
[16:55:56] FrostCandy: Ah ok, so testing is the best thing to do here as it could be diff dependign on dirvers
[18:21:24] craysiii: I'm attempting to learn RSpec, and having trouble writing a certain test. I'm trying to determine whether a Module has been extended in a Class instance during initialization. Seems like I can't use #ancestors, as it's an instance and not the class itself. Any other ideas?
[18:23:20] apeiros: your phrasing is confusing. you mean you want to test whether `Foo.extend Bar` has been used? if so, `Foo.is_a?(Bar)`
[18:26:54] apeiros: >> module Bar; end; some_obj = Object.new; some_obj.extend Bar; some_obj.is_a?(Bar)
[18:27:26] craysiii: good questions to ask myself, the previous gem I wrote I kinda hacked a solution together like this, trying to organize this one better, but beforehand trying to force myself to learn RSpec and more intricacies of ruby
[18:28:38] apeiros: ok. if you *always* extend instances with TradingPairAPI, then that code is terrible and `class REST; include TradingPairAPI; …` would be much better.
[18:42:20] vrotsok: Good evening every1... i just installed ruby on windows 7 and when i try install Rails by typing on cmd 'gem install rails' it outputs an error about nokogiri 1.8.1..... can any1 help ?
[18:43:43] craysiii: its documented on the RubyInstaller website. I agree with adaedra though, run ruby in a VM or on WSL
[18:44:18] adaedra: Ruby under Windows is just not worth it. You'll have trouble with gem compilations and other funky things.
[18:44:34] vrotsok: i just wanted to take a taste of RubyMine of intellij and i dont have enough space on HD so daaaaaaaarn
[18:46:13] vrotsok_: on github wikipage of devkit says that from 2.4 version of ruby they use 'msys2' which i've already installed
[18:56:41] banisterfiend: apeiros just curious, but do you know of any other projects like this? https://github.com/banister/diff_highlight
[18:56:46] banisterfiend: it seems so obvious yet i haven't seen something, it's also super-easy to do
[19:01:08] banisterfiend: oh no, this is just a git diff that i've sent through a syntax highlighter lol
[19:01:20] banisterfiend: it works similar to github diffs, it just highlights the lines that begin with +
[19:04:53] apeiros: banisterfiend: I'm not aware of something which does that, no. only projects which do either (diff or syntax highlight)
[19:06:01] apeiros: banisterfiend: would be really nice if git diff would support pluggable highlighters
[19:09:02] apeiros: and unnecessary I think? at least I thought there was an option to have colorless diff?
[19:21:54] baweaver: Only in Lisp can you be a Pyramid Schemer and a Racketeer and still get some Clojure afterwards
[19:28:19] catphish: i'm not really looking for assistance, but i want to moan, i've spent all afternoon trying to work out why under some specific circumstance (that i've yet to identify) both unicorn and thin are terminating my http responses part-way through a chunk
[19:31:56] baweaver: How much would people be interested in a book detailing some more advanced Ruby and black magicks?
[19:35:06] catphish: apeiros: yeah, looking into various places it could be a timeout, but i don't think that's what's happening this time
[19:36:34] catphish: i think i will try to print everything that's yielded to rack into timestamped files to i can make a reproducible copy of the problem
[19:39:53] catphish: i'll have my rack app log everything it yields to timestamped files and see if i can make a reproducible test case :)
[19:52:29] catphish: i also kinda already know what's happening on the outside of the app (it closes a tcp socket unexpectedly)
[19:53:22] catphish: anyway, hopefully i can reproduce it in a more controller manner (ie not depending on the rest of my production application and infrastructure)
[19:54:20] catphish: one of those nice bugs that only happens for one particular request from one particular customer :)
[21:47:28] zenspider: given a sequence of a/b "lines", group by author, then output UP TO the first a+ & b+ sequence. iow: either b+ a+ b+ or a+ b+
[21:48:33] wwalker: https://gist.github.com/wwalker/3271d4eaa14afca4cfe1c2b9bc925afd - irb pukes on this code, ruby runs it, any ideas?
[21:50:47] wwalker: but it says that while I'm entering the lines. I've done nothing to tell irb I'm at the end of input
[21:52:57] wwalker: right, before it throws an error I should have the opportunity to type in the last end
[21:53:22] adaedra: but it throws the error thinking you're done because it thinks you closed as many blocks as you opened
[21:54:47] zenspider: this is just gross code to begin with... and I don't understand coding at the def level by copy/pasting into irb
[21:55:27] zenspider: or just code using tests and then you need not use irb at all. I only use irb for exploratory fragments
[21:55:37] wwalker: the question is why irb is puking. its an intern's code, it just happens to break irb
[21:58:02] zenspider: it shouldn't manipulate the input (t_a.insert). it shouldn't use indexing. it shouldn't use for. it shouldn't use ...
[22:00:02] zenspider: the short answer is: irb doesn't have a "real" ruby parser and it gets tripped up on edge cases. File a bug with this example (you can probably pair it down to just the def + for) at bugs.ruby-lang.rog
[22:18:14] catphish: TDD to the extreme, i have no idea why this method does this, but it passes the tests :)
[22:23:51] catphish: zenspider: please explain, i don't understand what's wrong with my (test passing) answer
[22:24:54] zenspider: I described my problem description above. just because your code passes the assertions doesn't mean it is right.
[22:32:33] adaedra: This one's working, but I wouldn't call that pretty code: https://eval.in/private/b03b2715e7051b
[23:02:48] catphish: so, my rack server kills requests, seemingly at random, but not when i strace it, some nasty race condition there :'(