#ruby - 16 March 2018
« Back 1 day Forward 1 day »
[00:12:41] weaksauce: arand this is a touch more idiomatic and testable ruby... though some would do it differently https://gist.github.com/fiveNinePlusR/67c1a9de69bd3a3f80986b07581affe5
[00:42:44] arand: weaksauce: I would be inclined to name them something which reflect their mutating nature (i.e. with a '!'), is that usually done with methods like these?
[01:57:27] ycyclist: So I am trying to do a case statement on something.class, and it always goes to the else case.
[02:22:17] ycyclist: Sorry. I went around it by using if statements. I was in a hurry. Let me see if I can get it back.. Sorry man.
[02:29:51] ycyclist: I'll keep that around for tomorrow in case you already went away. I need to go in a minute anyway.
[03:12:58] baweaver: Give some of this a read - https://medium.com/rubyinside/triple-equals-black-magic-d934936a6379
[03:18:29] ycyclist: Yes, well I can use when "string". I am sorry. I already knew I could fix it without a case. Am I still being too dense?
[03:20:19] ycyclist: If I can do it with a case, I will, but if you think I can use case thingy.class somehow properly, I'll try it.
[03:21:11] ycyclist: The cases that work (and I just reran my tests on it, so I know they do) are Array MyThingy etc.
[03:22:02] ycyclist: but I think with quotes in a case is more helpfully readable than the if statements.
[03:27:39] ycyclist: Ok. I get it now. However, magic is not very auditable. I think making a string out of it, or using if statements is clearer. I really do appreciate your energies, however.
[03:28:10] ycyclist: I know that overloading can be handy, but it can also be a time-sink for research into vernacular when people don't want to spend such time.
[03:28:44] ycyclist: Please accept my complements, however, for your knowledge. That is good to know, and I may use it some day. Not this time, though.
[07:14:57] roelof: I try to solve level 4 of the ruby warrior. But I see this error ` comparising Fixnum with nil failed ` with this code : http://lpaste.net/363679
[07:31:47] ruby[bot]: dminuoso: # => undefined method `<' for nil:NilClass (NoMethodError) ...check link for more (https://eval.in/972990)
[07:31:53] ruby[bot]: dminuoso: # => comparison of Fixnum with nil failed (ArgumentError) ...check link for more (https://eval.in/972991)
[07:32:18] roelof: am now at level 6 of ruby warrior but im really stuck. I want that if the health is not enough the warrior steps one back and rest but of I use this code I see a message that I can only perform one action at the time
[07:33:26] roelof: yep . how I can make this work in ruby. I try to learn some ruby by using this site
[07:35:25] dminuoso: roelof: Your question is too general. Perhaps you are biting off more than you can chew?
[07:36:59] dminuoso: roelof: The book "Well Grounded Rubyist" is a frequently recommended books for beginners to Ruby and programming.
[09:27:55] ss942: funny behaviour when I type ruby -v as a root it says me 2.5.0 when I type this with casual user it says ruby is not installed
[09:30:41] dminuoso: ss942: "ruby is not installed" just means "I was not able to find an executable named `ruby` in any of the directories specified in PATH"
[09:39:05] WhereIsMySpoon: Burgestrand: hey :) wonder if you’re up for solving a little conundrum I’ve come up against again? :)
[09:39:46] burgestrand: WhereIsMySpoon part of the deal is that you invite everybody to solve it and not just me :) i.e. post it in here and hope for luck
[09:41:01] WhereIsMySpoon: Alright then, the output of the EasyAudio::Stream is buffers of floats. I (and burg who was helping me yesterday) figured it would be floats -1 to +1, however it seems to be of a larger range…I”m getting numbers from +7 to -6 or so even by moderately raising my voice
[09:41:26] WhereIsMySpoon: Wondering what the heck these numbers are…from the code its definitely amplitude, but why its not measuring in -1 to +1 I have no idea
[10:06:47] burgestrand: WhereIsMySpoon your audio library should tell you what the range is I believe, i.e. portaudio docs, if they don't it's probably some standard format
[10:09:28] WhereIsMySpoon: Burgestrand: EasyAudio is sending stream[:sampleFormat] = API::Float32 as the format, which is defined in ffi-portaudio as 0x1
[12:02:03] plasmik: I need to compile some C-Ruby stuff, it has 'require mkmf' line, and this mkmf file spits errors and tells me to install developer tools
[13:11:20] arup_r: I want to match if a string contains upper case, lower case, and numeric characters. What I tried http://rubular.com/r/vHGcQmx3l7 is wrong. What is the correct regex ?
[13:15:10] phaul: you have lower case z where you meant upper case? otherwise you get a match if your regexp matches any part of the string. I'm guessing you want too match if the regexp matches the entire string. to do that use begin string end string anchors in the regexp \A, \z
[14:27:04] morfin60: i am not sure how implement that: i have class A and classes B,C,D inherited from this class, all of them have method to parse all pages called collect_blocks of resource(pool) and i parse them until there is no output, this method is protected and used in multiple public methods of classes, any clue how can i pass code to process single page?
[14:28:30] morfin60: i realized how dumb was idea trying collect all blocks in huge array and want to rewrite code to process page-by-page
[15:29:39] yrstrly: Hi, could somebody help me? Got a really basic question about classes I have these two classes : https://imgur.com/a/g4L6N and when I run these code lines Todolist.new, Todo.new("get the milk"), @to_do_list.add(@to_do), I get the error undefined method `add' for nil:NilClass (NoMethodError) even though it's clearly defined in the class and is being applied to an instance of the class
[15:41:28] mzo: even if it did exist, it's just an array. not a Todolist. so you wouldn't call .add on it
[15:43:35] yrstrly: why is it not? it's defined in the initialize method for the class, so whenever Todolist.new is entered @to_do_list, an instance of the class Todolist, which is an empty array, will be created?
[15:51:50] WhereIsMySpoon: im trying to use easy_audio https://github.com/lsegal/easy_audio and im just getting hangs like 70% of the time I try to close an EasyAudio::Stream object
[15:56:52] phaul: yrstrly: If you want your code to be debugged, paste the whole thing in a gist. see topic.
[16:00:06] yrstrly: I'd just like to know how to properly generate an instance, if I've not done it correctly, as I understood it, if you call Todolist.new, you'll have an empty array assigned to variable @to_do_list
[16:04:32] yrstrly: Thanks phaul, so there's nothing wrong with how I've defined the classes and methods?
[16:09:26] yrstrly: It now runs, but when I call add and then print the array, it hasn't been pushed into it
[16:23:49] Jeff_D: Can someone point me to equivalent Ruby code for the `gem install --explain` command? Capturing and scraping terminal output doesn't seem like the best way forward
[16:28:18] havenwood: Jeff_D: For example, try: Gem::Specification.find_by_name('rails').dependencies.map(&:to_s)
[16:52:30] Jeff_D: @havenwood Thanks for that; I was looking for something that does the equivalent of, say, `gem install rails --explain`, which lists specific versions of dependencies, dependencies of dependencies, and so on; it seems odd that I have to walk the dependency tree and build a gem list explicitly. But if that's what it takes, oh well
[20:06:08] gizmore: made a new hacking challenge... training programming level 3/10 : https://www.wechall.net/en/challenge/britcoin/
[22:04:12] IshMael_: Can someone explain to me, why there isnt a self on the key?(method_name) on the second line?
[22:05:54] phaul: IshMael_: it's about what self is. If you have time watch https://youtu.be/X2sgQ38UDVY, that should explain what self is
[22:09:42] phaul: basically your gist has too little to tell what self is. But when you are inside a def inside a class statement self would refer to the instance of the class that receives the instance method.
[22:10:32] phaul: it can'tbe ommited in certain cases, when the syntax confuses the interpreter, like slef.class
[22:11:39] IshMael_: phaul: the code is from the Hashie GEM , which is an example from the book "Metaprogramming Ruby 2" by Paolo Perrotta
[22:13:11] IshMael_: so i just wondered why there is a self. when i also can access the keys in that hash without the self in front
[22:14:19] phaul:  requires self because the intrepreter doesn't like a bare  operator without a receiver it. key? is fine with an implicit receiver. It's mostly just syntax really
[22:16:42] apeiros: the reason being that they pass a block. and the syntax sugared form can't take one
[22:18:03] apeiros: not sure then why they used `self.(method_name, &blk)` instead of `self[method_name, &blk]`
[22:19:05] IshMael_: apeiros: thats right! i took me not long to get into ruby. but well the topic metaprogramming and the concepts behind are sometimes like a hard, little nut until i can grasp it
[22:21:00] IshMael_: apeiros: i hope you are right .. i've just worked trough the first 60 pages, but that gave already a lot of insight. and im sure there is more to come
[22:21:11] apeiros: for example: there are no class methods in ruby, only instance methods. what people call class methods in ruby, are really just instance methods too.
[22:22:43] phaul: altough lot tools like Yard calls them class methods, maybe even ri - I'm not sure
[22:23:40] IshMael_: phaul: what me got worried was that in the ruby source there seems to be a different name for eigenclasses(singleton classes) and metaclasses