#ruby - 19 June 2016
« Back 1 day Forward 1 day »
[02:58:28] shevy: and if it is easy to customize to your own personal style or a project specific style, that is also good
[04:25:57] riceandbeans: shevy: can I get your opinion on a rubocop recommended correction on some code?
[04:28:21] riceandbeans: shevy: https://github.com/cburnette/boxr/blob/master/lib/boxr/folders.rb#L144
[04:28:39] riceandbeans: shevy: rubocop says result is useless and should be show as such be being prepended with _
[04:48:22] shevy: for response, there is a difference between response and _response that will be on the parser level, if you use the leading _ before response then ruby will not issue a warning about an unused local variable
[05:00:55] gking: I know I can use CSV.parse too but I see that HTTParty has it built in already but not sure how to use it.
[05:01:53] gking: Or does it just auto detect the file type? It doesn't seem to always work in that case.
[05:43:49] shevy: yeah, this is where rubocop just does what the ruby parser does. to be honest, rather than using _, I wonder if in these cases it would not better to disable that warning altogether from the ruby parser side
[05:59:59] ruby[bot]: riceandbeans: we in #ruby do not like pastebin.com, I reposted your paste to gist for you: https://gist.github.com/df40981118e5526b15468888999aa80c
[05:59:59] ruby[bot]: riceandbeans: pastebin.com loads slowly for most, has ads which are distracting and has terrible formatting.
[06:16:57] ruby[bot]: ruby[bot] kicked NSABear: is a bannable offense, see http://ruby-community.com/pages/user_rules
[06:35:43] baweaver: basically you need persistence beyond the scope of a script, and that's what a database is for.
[06:49:30] gogo_: Arcaire: yup..thanks it was more about general education. i wont really do anything
[07:07:39] Hanmac: riceandbeans: if you use some delegator object like with https://gist.github.com/Hanmac/4619845 you can do it
[12:16:17] Hanmac: mimtf: depends, do you already have experimence with other programming languages?
[12:23:01] Hanmac: mimtf: i think for the first look that would be useful: https://www.ruby-lang.org/en/documentation/quickstart/ or that http://tryruby.org/
[12:23:47] marahin: Has anyone used https://github.com/JEG2/highline ? I'm wondering if it's possible to show in realtime how many characters has the user provided to the input
[12:24:17] marahin: E.g. twitter-like behavior: user fills in a post, and while typing it shows how many characters he used
[12:30:41] Hanmac: mimtf: there are other stuff in getting started: https://www.ruby-lang.org/en/documentation/ like "Why’s (Poignant) Guide to Ruby"
[14:50:36] salexa: has left #ruby: ("PART #diaspora :PART #gnu :PART #wordpress :PART #RubyOnRails :PART #fsf :QUIT :Leaving.")
[15:45:16] fujinuma: why I get uninitialized constant Person::Subscription error in this code? http://vpaste.net/flRXc
[16:01:05] shevy: perhaps the did you mean gem will help there, it already has some support for it: https://github.com/yuki24/did_you_mean#displaying-a-warning-when-initialize-is-incorrectly-typed
[16:04:49] mimtf: Apparently all Mobile Internet Service Providers (ISP) block any kind of incoming connections. So, no matter which port I want to forward it will be blocked by the ISP. (connection requests will never reach the router).
[16:18:34] riceandbeans: if you do foo = get(uri) instead of foo, response = get(uri) what would happen?
[16:21:53] jhass: riceandbeans: what will happen is that if get returns an array, its first two values will end up in foo and response, if it doesn't response will always be nil
[16:21:58] shevy: if it returns an array you will get: a, *bcd = %w( a b c d ) # => ["a", "b", "c", "d"]; a # => "a"; bcd # => ["b", "c", "d"]
[16:32:59] riceandbeans: so it is sort of necessary to use it in order to keep unwanted data out of another variable
[16:59:42] jokke: hey, about rack middleware: i want to write a middleware for my sinatra app that just parses some headers and adds stuff to env. how can i do this without actually handling the whole request?
[17:12:24] romistrub: I have a couple of classes that are namespaced by a module (the module is included using 'require'). How should I name the files that contain, for example, Framework::WebSocket
[17:16:29] romistrub: waaaaiiiit... does that mean I have to create subdirectories for each module? :|
[17:17:08] shevy: riceandbeans well you are in full control of what data to use and what not; even if you don't put it all in one line, you can use methods on class Array or class Hash to .select or .reject what you want and don't want
[17:19:54] riceandbeans: shevy: if you only want to keep the first element of the array is it cleaner to do arr1, arr2 = whatever, or to do arr1 = whatever and then chop off everything but the first element?
[17:26:06] shevy: riceandbeans I think using methods like the above .shift will be the best, I found that in complex setups, my brain takes longer to process so I try to go for minimal complexity and maximal elegance whenever possible
[17:27:58] spudowiar: The method is just `def obsolete_files (existing_files - new_files - new_dirs + replaced_files).to_a end`
[17:40:15] fujinuma: how to run setup() method without test_* methods? kind of testing if it correctly instantiates.
[17:43:21] fujinuma: ljarvis: reasonably setup() should trigger without test_* methods its existence is to be instantiate class object.
[17:44:16] iCHAIT_: CAn someone give me some pointers on how to port this python method - http://dpaste.com/0R06VW4
[17:44:29] ljarvis: fujinuma: no, it's existence is based on triggering before a test_* method is called
[17:44:49] adaedra: iCHAIT_: simple. Look at what the method does, throw away the python code, code it in Ruby.
[17:48:05] iCHAIT_: SO I want to know a way by which I don't have to call a func, but can still use its object.
[17:49:14] iCHAIT_: So I want to use the object of that func in my ruby code without actually making a call to it.
[17:49:33] ljarvis: are you sure this exact code passes? because I can spot a couple of issues that should mean it breaks altogether
[17:52:04] ljarvis: anyway, you can't do exactly what you want because Ruby doesn't have first-class functions/methods like Python does (which allows you to inject methods as mocks, I think)
[17:52:13] spudowiar: Can you return an array that you instantiated in a method, from a method in Ruby
[17:52:26] ljarvis: so I would probably avoid mocking this and test it fully. I don't see a reason for the mock myself
[17:52:59] ruby[bot]: it seems like you are asking for a specific solution to a problem, instead of asking about your problem. This often leads to bad solutions and increases frustration for you and those trying to help you. More: http://meta.stackexchange.com/a/66378
[17:53:37] spudowiar: jhass: basically, I have an array and inside the method it's fine, when I return it the caller sees an empty array
[17:53:49] ruby[bot]: We can't help you without your code, please post it to https://gist.github.com
[17:54:03] spudowiar: ljarvis: the only line of code in the method is "(existing_files - new_files - new_dirs + replaced_files).to_a"
[17:54:58] ljarvis: well, that code there isn't probably not broken. So I'd start looking a bit further up the chain
[17:55:37] spudowiar: replacing it with "a = (existing_files - new_files - new_dirs + replaced_files).to_a; puts a; return a" prints the correct stuff
[17:56:51] spudowiar: it's being called from https://github.com/jekyll/jekyll/blob/master/lib/jekyll/cleaner.rb#L15
[17:57:55] jhass: show the _exact code_ with 5 lines of context in each direction you used to prove that obsolete_files is empty
[18:00:01] spudowiar: I tried doing `return 1` and I got a stack trace from some other random thing :)
[18:00:32] jhass: iCHAIT_: http://gofreerange.com/mocha/docs/Mocha/Expectation.html#with-instance_method
[18:01:38] ljarvis: spudowiar: I'm mostly distracted by your love for hitting enter after every couple of words :)
[18:04:14] spudowiar: And it's not fair on everyone else, just because I'm too stupid and immature :(
[18:11:21] yesthatallen: i'm still looking to speed up ruby installs.. is there a way to ./configure --without-test or the like?
[18:12:44] yesthatallen: but in a place where I'm compiling ruby for use to run an app, never development, I can't help but wonder what could be skipped
[18:14:46] iCHAIT_: ljarvis: Because I just want to have an object of the function and not actually use it.
[18:17:15] iCHAIT_: ljarvis: I just want to test the method create_or_update gets called with the correct parameters.
[18:17:46] ljarvis: iCHAIT_: right, but surely you can test that by checking the object that create_or_update returns (or what it mutates)
[18:18:46] ljarvis: e.g. something like https://gist.github.com/leejarvis/619642ae94919b021a7ab83b4d3867c1
[18:19:29] ljarvis: also I generally dislike mocks because they're overused and they introduce misdirection
[18:20:41] iCHAIT_: ljarvis: Okay, that looks interesting, BTW, what you mentioned is exactly what the @patch in the python code is doing, it creates an object for the func. create_or_update, stores the result in the arg. mock_create_or_update and then asserts.
[18:21:07] Lewix: ljarvis: you can always implement anything it doesn't mean it's provided by default
[18:21:55] ljarvis: do you want a *method* that does something equivalent? because you didn't say that
[18:22:10] iCHAIT_: ljarvis: I didn't understand this line in the gist - assert_equal "omg", time.something
[18:22:19] Lewix: there isn't a method similar to unshift in the standard library that effectively does what #unshift do but does not modify the value in place. correct?
[18:26:58] ljarvis: iCHAIT_: I am, mocking is useful for some things, but nothing has yet demonstrated that it would be useful for what you're doing
[18:53:17] jhass: wixad_: so my connection dropped and most of what I said didn't come through. .dup and .shift is the most analogous technique, these days you'd use each_with_index, more alternatives are just using @@lcdStates[i] or .each and keeping a manual counter
[20:12:37] riceandbeans: https://gist.github.com/strangelittlemonkey/1bc72bd86f7ad0b3ccd770b8f72bb8f0
[20:14:38] shevy: I have not fully gotten to the part which one you specifically need, but this appears to be solvable via a .select, inside it you can use .include?
[20:16:05] riceandbeans: well, the complaint was that in this manner, for larger arrays it would have to scan the last array every time and be increasingly slow
[20:23:40] riceandbeans: I mean, if it was guaranteed to be numeric, and if you did a binary search in the array each push to insert in numerical order I guess maybe it would be faster for larger arrays?
[20:34:39] shevy: I don't know how you can do sub-selections within array elements without checking the rest of the array in ruby
[20:41:33] riceandbeans: jhass: al2o3-cr can you explain to me the idea in general for what you would do?
[22:31:33] leitz: Okay, easy question. If I my_module.method(object), and the method would change the object, is the original object changed once the method ends?
[22:35:58] Radar: If you have some small code which can repro the issue then we can point out why it's acting that way
[22:36:31] leitz: Let me work on it. I'm right at the edge of my understanding, and trying to simplify the code.
[22:51:53] diffy: Hi! I have tried to google, no luck. Does anybody know how to store an entire array to a google drive spreadsheet? I have the google-drive gem up and running, authenticated and it is working. But I found no examples on how to do this.
[22:53:57] leitz: Module question. This line: https://github.com/LeamHall/CT_Character_Generator/blob/refactor_character/lib/CharacterTools.rb#L29
[22:54:11] leitz: Calls this line: https://github.com/LeamHall/CT_Character_Generator/blob/refactor_character/lib/Marine.rb#L35
[22:54:57] leitz: Since the second line listed is in a module called "Marine", I thought it would work if the method was defined "def self.first_term()"
[22:55:22] leitz: It does not work if I use self, but if i make it "def Marine.first_term()" it works.
[22:56:29] shevy: using self. is usually better since you don't have to change the name at any later time, if you ever rename something
[22:56:44] leitz: for the record, I happy with "you need to look at X" instead of detailed code. I learn more that way.
[22:57:40] leitz: Ah. That's what I thought, but self doesn't work. If I make it "Marine.first_term", it works.
[22:58:59] shevy: class Marine; def self.yo; puts 'I am a Marine'; end; end; Marine.yo # => I am a Marine
[22:59:25] shevy: by the way I would put all non-conditional requires right at the top of the .rb file
[23:01:06] leitz: Yeah, what's going to happen is that whatever career chosen, 'Marine', etc, shoudl get required at that point.
[23:01:43] shevy: the other requires appear inside a module namespace, for no real reason that I can see
[23:02:18] orangey: I'm playing with Discourse (a rails app) and trying to write a plugin to replace a class MessageBuilder
[23:02:30] orangey: However, my plugin is ignored. I think I don't necessarily understand the basic concept here..
[23:04:01] orangey: When I try to run the rails server, I get: "/vagrant/lib/email/message_builder.rb:20: warning: already initialized constant Email::MessageBuilder::REPLY_TO_AUTO_GENERATED_HEADER_KEY", which I gather means that it's not understanding what it should do?
[23:06:20] shevy: you will see that there will be no difference between: require 'foo'; module Bar; ... and: module Bar; require 'foo'
[23:14:05] leitz: Oh, cool. using a totally different set of files. If the calling program includes Marine, and the Traveller module does not include Marine, I can still call Marine.hello from inside Traveller.
[23:15:07] leitz: So, a module question. Should it require modules it calls, or assume the program calling it will require them?
[23:17:22] leitz: That is, if CharacterTools uses methods from Traveller, should it require Traveller? I'm tryng to break things up into Single use bits.
[23:21:22] orangey: Any thoughts on how to replace a class? I've posted the repo here: https://github.com/tareko/replyto-individual/ . It's the plugin.rb that should replace the MessageBuilder function but seems not to
[23:25:27] i8igmac: im trying to read from a binary file. remove the header, and save the rest of the binary data as file.mp3
[23:29:03] shevy: leitz I tend to start with constant definitions usually, then module-specific methods on the namespace, like: module MyGame; def self.start
[23:31:38] shevy: leitz in general, if a file depends on code that is in another file, add a require statement
[23:32:01] leitz: shevy, thanks! I've turned the big character class into a data storage pool with accessors. Everything else is being broken up as well.
[23:38:34] i8igmac: i guess it is working, i was oping the mp3 with sublime text to see if it looks ugly binary, but auto shows hex
[23:45:33] lupine: surely sniffing files from a web service must be the worst possible option for illegally downloading media?
[23:46:41] lupine: personally, I have a tape recorder with a microphone I hold to my radio's speakers