Activity Graph

Page 1 of 2 | Next »


[18:13:13] newdan: has joined #ruby
[18:16:25] newdan: Does anyone know the Ruby equivalent to `def something(*args, **kwargs):` in Python?
[18:17:10] newdan: I think I can use the same *args syntax to get varargs, but what's the equivalent for Ruby's keyword arguments?
[18:19:19] newdan: ...ah nevermind it is apparently the exact same syntax, cool
[19:36:29] newdan: has left #ruby: ("ERC (IRC client for Emacs 25.1.1)")


[13:08:37] newdan: has left #ruby: ()


[14:16:00] newdan: has left #ruby: ()
[16:05:40] newdan: has joined #ruby
[16:07:35] newdan: Is there a way to do `def an_instance.method` but in a non-syntactic way? I want to use a block so I can access outer vars. (I'm writing a test and I want to set a flag if a method is called. So the body is something like `super.tap { got_called = true }`)
[16:10:19] newdan: shevy: It does that on the class, but I don't want to change the whole class, I just want this feature for this one test
[16:12:42] newdan: `an_instance.define_singleton_method(:some_method){|*args| super(*args).tap{ got_called = true }}` seems to do what I'm after... Does that look wrong to anyone? (Other than that it's all on one line, in my source it'll be expanded)
[16:14:24] newdan: Yeah, I am not gonna commit it looking like that. Just didn't wanna have a multiline paste into IRC
[16:23:52] newdan: I dunno. Doesn't seem *that* complex imo, and with a comment saying the whole point is to just set got_called if the method gets called, I think it's not too hard to puzzle out. My test makes no sense if some other part of the system results in that method not being called so I think the small complexity in this specific test is acceptable
[16:24:14] newdan: I mean I would be happy if I could do it in a simpler way
[16:28:10] newdan: smathy: Not in a block. If I declared with `def an_instance.some_method(*args)` then yes


[14:52:43] newdan: has joined #ruby
[16:00:35] newdan: avril14th: AFAIK Matz has plans to eventually remove the GIL (which should allow multicore) but that is very far in the future
[16:00:44] newdan: avril14th: JRuby does support multicore now (I think)
[16:07:12] newdan: avril14th: Maybe this will help
[16:11:13] newdan: Wow, Rubinius has a GVL?
[16:13:00] newdan: Oh I see a Rubinius blog post talking about the GVL but that's from 2011
[16:14:11] newdan: hxegon: Technically MRI is not currently maintained, Ruby's implementation is now YARV
[16:14:28] newdan: hxegon: So the same problem still exists but its name changed when Ruby switched from MRI to YARV
[16:18:21] newdan: shevy: Same here, trying to download the .tgz file gives me some XML
[17:41:41] newdan: has left #ruby: ()


[13:15:16] newdan: has joined #ruby
[16:47:39] newdan: wolffles: ????
[17:42:53] newdan: Quit: leaving
[19:32:17] newdan: has joined #ruby
[21:10:36] newdan: Remote host closed the connection


[14:42:38] newdan: has joined #ruby
[20:34:19] newdan: maasha: How did Oracle destroy Java? By adding lambdas and streams?
[20:35:39] newdan: headius: Those bastards
[20:55:46] newdan: Sh1rt: are you currently logged in as root?
[20:56:41] newdan: Sh1rt: Then yeah
[20:57:23] newdan: Sh1rt: You're sure you're just not in an "administrator" account? The "whoami" says root?
[20:57:28] newdan: *whoami command
[21:06:26] newdan: Sh1rt: At this point you'd know better than me. I only work as a non-root user and use sudo
[21:06:43] newdan: Sh1rt: Not sure about how the su command works, etc.
[21:29:46] newdan: TomyLobo: it tells you exactly what versions are in use. So there's no question what dependencies are where
[21:30:24] newdan: TomyLobo: My job when I first came here didn't commit Gemfile.lock and they used deploys from source-control. So it was anyone's guess what server had what version of what at any given time
[21:48:02] newdan: ASTP001: What is that syntax? Why not just "- if false"
[21:51:28] newdan: ASTP001: Can you give a bigger snippet? Something is wrong outside of this part of your code
[21:51:34] newdan: ASTP001: That error doesn't make any sense
[21:52:46] newdan: ASTP001:
[21:53:23] newdan: ASTP001: I'm pretty sure something else is wrong. I don't even understand how "-if (false)?" works, tbh
[21:53:43] newdan: ASTP001: If I use that, I get a syntax error
[21:54:08] newdan: Also I can take out the else branch and that works as well
[21:54:41] newdan: ASTP001: Yes, indentation is significant in haml
[22:05:34] newdan: soLucien: It's like a cmp() function or Comparator in Java
[22:05:49] newdan: soLucien: In Python, cmp(1, 10) is also -1
[22:36:50] newdan: Remote host closed the connection


[13:31:27] newdan: has joined #ruby
[16:41:19] newdan: centrx: What about tcl?
[16:42:42] newdan: ponga: Take it up with #python. They decided to do that to keep it simple, ...or something. I agree with you though ponga I don't like it
[16:43:32] newdan: OOP in Ruby is much cleaner to read
[16:46:13] newdan: xapak: Just curious, what language are you used to where [""] is considered false?
[19:11:13] newdan: In Python when I have an uncaught exception in the shell, I can do "import pdb;" and it will let me debug from the exception point, post-mortem. Is there anything like that in Ruby?
[19:13:20] newdan: snockerton: So if the exception's already happened, you're out of luck?
[19:16:41] newdan: Ox0dea: Haha, cool thanks
[19:17:02] newdan: I wonder why the builtin Ruby debug feature seems... ...relatively unloved
[19:44:48] newdan: shevy: When running on the terminal you can use 'ruby foo.rb > /dev/null'
[19:50:27] newdan: Waheedi: ?
[21:26:32] newdan: Remote host closed the connection


[03:48:46] newdan: Remote host closed the connection
[14:28:52] newdan: has joined #ruby
[14:40:30] newdan: kbni: Imo coming from Java and Python I *love* that zero-arg methods don't use parens in Ruby :D
[14:44:08] newdan: shevy: As a Python user... not all of us lol. I don't love the () and I don't love explicit self (or the super awkward super)
[14:45:04] newdan: kbni: I agree, but the method is explicitly in a class. I don't see how passing self as first arg all the time helps anything, really
[14:45:47] newdan: shevy: The things about Python I like compared to Ruby are the modules/namespacing, and also I find Ruby's method scoping a litle surprising
[14:46:30] newdan: kbni: Sorry, I meant declaring self as the first arg
[14:47:53] newdan: shevy: Yes. This probably sounds trivial but it would almost be fine if Ruby modules didn't require everything in the module to be wrapped in the module block. Something like e.g. the package statement in Java that says "Everything in this file belongs to this module" would be nice imo
[14:49:21] newdan: aegis3121: Flat is better than nested :) I just find it ugly to have to indent everything in my .rb file in order to not pollute the global namespace
[14:50:23] newdan: kbni: I like that tbh. Better than __neq__ or __iadd__ imo
[14:50:52] newdan: I also like two-space tabs
[14:50:58] newdan: Well, two space indents
[14:52:15] newdan: kbni: Comply to Rubocop
[14:55:19] newdan: ljarvis: Weird, def child_names; @child_names; end
[14:55:29] newdan: ljarvis: Why wouldn't they just use attr_reader :child_names?
[14:59:23] newdan: kbni: It's a valid character in method names. So is !
[14:59:33] newdan: kbni: It's just a convention
[14:59:52] newdan: kbni: Not actual language syntax. It can't be is_a(Thing)? because then ? wouldn't be part of the method name
[15:01:28] newdan: kbni: Lisp/Scheme do things similarly. In Scheme you have (string->number "32") giving 32 and (string? 3) giving #f
[15:12:42] newdan: kspencer: Have you tried Ocra?
[15:13:06] newdan: kspencer: Ocra is for packaging Windows stuff
[15:13:17] newdan: Might help
[15:29:06] newdan: diegoviola: What book? I like Ruby, but if the book's not written for Ruby, why not use the language it is written for?
[15:29:35] newdan: diegoviola: You should be mostly fine either way but there's always the chance for some small difference in the regex engines to give you a minor headache while you're trying to learn
[17:21:54] newdan: theslow1: That's fine
[17:23:24] newdan: xapak: No worries, ruby[bot] took care of it, you're not in trouble lol
[17:38:29] newdan: tarantul: Is it possible that record['_type'] *is* nil?
[17:38:49] newdan: tarantul: e.g. {"_type" => nil}
[17:40:54] newdan: tarantul: Oh. ...well then there you go
[17:42:30] newdan: ljarvis: Well, the assignment shouldn't be happening if has_key?("_type") is false
[17:42:36] newdan: ljarvis: Which it should be according to his output
[17:44:53] newdan: ljarvis: But his variable is previously defined
[17:45:19] newdan: ljarvis: The second line of his code is "p type_name"
[17:45:25] newdan: ljarvis: Haha, I agree
[17:46:23] newdan: tarantul: What is record.class
[17:47:09] newdan: tarantul: I don't think Ruby is the thing that's strange here
[17:49:47] newdan: tarantul: wat
[17:50:08] newdan: tarantul: Uh... you're welcome I guess
[18:00:11] newdan: tarantul:
[18:00:43] newdan: tarantul: So something else is happening that you're not telling us or perhaps you're unaware of
[18:03:07] newdan: tarantul: So the code on the server is different from the code you're pasting us. Either record is different or the code as written is different (and perhaps contains a typo) or something else, I dunno. But it's not really possibly to help you since the code you're giving us doesn't lead to the output you're giving us
[18:09:46] newdan: pareidolia: Probably so it doesn't cause an error when pasted into irb
[18:10:31] newdan: Other representations work as literals you can paste back into irb/Ruby source
[18:12:28] newdan: pareidolia: Oh, well maybe that's why then
[18:12:40] newdan: <- not an expert
[22:36:54] newdan: Remote host closed the connection


[15:17:03] newdan: has joined #ruby
[16:33:35] newdan: bjensen82: Count up the days in all months from start to end, divide by six and store as span, go [start_date, start_date + span], [start_date + span, start_date + span * 2], etc.
[16:35:37] newdan: bjensen82: I don't understand what you mean
[16:39:36] newdan: bjensen82: So just + 1 to the start_date of the next span?
[16:47:21] newdan: bjensen82: Some small variant of that should work, or it should be easy to write a loop you're satisfied with. Unfortunately for me I'd probably have to doodle with a pen and paper for five minutes to come up with a perfect answer, and that's too much of a commitment for me right now
[16:48:02] newdan: [start, start + span], [start + span + 1, start + span + 1 + span] etc should work
[20:21:55] newdan: hxegon_: Django prior to 1.8 use optparse. Any reason you don't wanna use argparse?
[20:22:16] newdan: hxegon_: ...whoops wrong channel, disregard that answer
[20:31:44] newdan: maletor_: You want an intersection on two objects? I don't fully understand the question
[20:48:47] newdan: kristian_on_linu: What do you mean? Looks like an array of symbols
[20:49:15] newdan: I am insteresting this issue: Can you any suggestion to me
[20:49:20] newdan: Whoops wrong button
[20:49:37] newdan: kristian_on_linu: Look here
[20:49:55] newdan: kristian_on_linu: Instead of strings, use symbols. [:abstract, :month_numeric, :url]
[20:50:33] newdan: The change in lib/jekyll/scholar/defaults.rb looks like the type of format you want to use
[20:55:57] newdan: kristian_on_linu: I am not too familiar with Jekyll. There's no configuration .rb file?
[20:56:15] newdan: kristian_on_linu: Why not ask #jekyll?
[21:23:48] newdan: Why bother with the .in extension?
[22:30:34] newdan: Remote host closed the connection
[23:48:02] newdan: has joined #ruby


[14:40:55] newdan: has joined #ruby
[14:48:20] newdan: Almoullim: what's the other language?
[14:49:03] newdan: Oh lol what
[21:41:36] newdan: ympeg: Fltk?
[21:47:23] newdan: ympeg: Another (kind of far out) option is to use JRuby with something like JavaFX
[21:47:39] newdan: I don't really know a well maintained Ruby GUI lib. Fltk is pretty old (although it worked well enough last time I used it)
[21:48:40] newdan: ympeg: Maybe this one would work well
[21:50:43] newdan: ympeg: I would probably try FXRuby before Fltk since it seems maintained, if you choose to stick with Ruby. (Note it's FXRuby uses FOX toolkit not JavaFX)
[21:57:22] newdan: Darmani: But other people in this channel would find it a little noisy
[22:06:49] newdan: Yeah, when I played it, if you guess a letter wrong you draw another part of the hangman
[22:08:03] newdan: Darmani: Weird. I don't see how that makes any sense... so you can't have large words?
[22:35:48] newdan: Remote host closed the connection


[14:44:36] newdan: has joined #ruby
[14:53:34] newdan: platzhirsch: unless is like inverse if
[14:53:54] newdan: platzhirsch: false && false and false && true are both false, so they satisfy the unless
[14:56:29] newdan: platzhirsch: I agree, for anything non-trivial unless is very confusing
[14:56:43] newdan: I mean, it has predictable behavior but it just makes the code confusing to read
[14:59:02] newdan: newbie22: what IRC client do you use that puts "*: " in front of all your messages?
[14:59:50] newdan: platzhirsch: Correct
[15:29:07] newdan: ImJune: Rails and Django are pretty similar
[20:40:52] newdan:
[20:41:06] newdan: "Constructs a Version from the version string. A version string is a series of digits or ASCII letters separated by dots."
[20:43:00] newdan: riceandbeans: Yeah, that sounds right
[20:43:15] newdan: riceandbeans: You can always just launch irb/pry and play around to make sure it works how you expect...
[20:54:11] newdan: apeiros: That last bit is basically exactly what he already said
[21:04:21] newdan: sediment: What gem?
[21:08:21] newdan: sediment: I'd try Nokogiri or something like that, personally
[21:09:08] newdan: Yeah the github page for truncate_html is not very helpful
[21:09:16] newdan: Their only "example" just doesn't work
[21:10:01] newdan: sediment: Well, that's why I'd suggest Nokogiri. It'll parse the HTML and let you find all text content inside
[21:10:15] newdan: It's a very small subset of Nokogiri but I think it'd do the trick
[22:21:17] newdan: shellie: If you're new it might be hard to read some libs. But if it were me I'd just go find some highly starred repos on Github and dig around
[22:22:58] newdan: Ox0dea: That's a good idea. Although often I read stuff like that and wonder "Are people allergic to variable names with more than one letter?" (although haven't tried CodeWars specifically)
[22:23:57] newdan: Ox0dea: I agree. But I routinely see those sorts of post solutions sites devolve into code golf
[22:24:53] newdan: shellie: rubocop
[22:29:02] newdan: riceandbeans: Just try it in pry/irb
[22:30:44] newdan: riceandbeans: Depends on your application
[22:38:00] newdan: Quit: Lost terminal


[15:08:26] newdan: has joined #ruby
[16:10:46] newdan: has joined #RubyOnRails
[16:34:36] newdan: newbie22: Not quite 'idiomatic' but still might be helpful:
[19:02:36] newdan: prestorium: I'm not an expert but I think the glossary just defines terms in the language
[19:03:41] newdan: prestorium: So you can say you name your classes for words in the UL, and the glossary defines terms in the UL (and maybe other terms too)
[19:04:22] newdan: prestorium: It is. The point of the UL is that when someone says something everyone has a very specific idea of what it is
[19:05:21] newdan: prestorium: Your UL doesn't define anything. Tomato and Vegetable are terms in your UL. Something else (like your glossary) defines that a Tomato is a Vegetable
[19:05:41] newdan: There's overlap
[19:05:44] newdan: Don't worry too much about it
[19:07:18] newdan: With a glossary, usually. Or maybe with UML diagrams if that's appropriate
[19:07:50] newdan: Like I said I'm not exactly an expert. The idea of the UL is just that you have these key terms that are not ambiguous, that's all
[19:09:16] newdan: If you are doing a grocery app then "Product," "Category," "Supplier" might all be terms in your UL. So when you write documentation you write using those words, when you write code your definitions use those words, your glossary explains those words, etc.
[19:09:30] newdan: prestorium: Use whatever you want
[19:09:38] newdan: Google Docs would work fine
[19:09:47] newdan: As long as it's easy to share with your team
[19:37:59] newdan: uberjar: JRuby is definitely sweet. But all new Ruby features go to MRI first and MRI is good enough for most
[19:38:12] newdan: uberjar: Also the JRuby startup time is in fact quite painful for shell scripting
[19:40:14] newdan: uberjar: So if that matters to you, then it's awesome that JRuby is there for you to switch to
[19:44:28] newdan: uberjar: If you're running stuff like rake and bundler constantly then it adds up very quick. That said, I agree, JRuby is awesome. If I had any trouble scaling a Ruby app the first thing I'd do is try and port it to JRuby and see if that didn't solve my problem
[19:49:25] newdan: Yeah I think that's easily the biggest hurdle to "just switching" to JRuby... the native extensions
[19:52:29] newdan: choke: That's a shame, the JVM is very solid
[19:52:54] newdan: That said, if it works it works. Sounds like you have your situation figured out either way...
[19:58:20] newdan: uberjar: Do you have some stake in JRuby?
[20:01:05] newdan: Yeah I didn't know about Torquebox until right now. Might check it out later
[20:47:29] newdan: Rails site needed an update. It looked a bit dated
[20:53:42] newdan: kallisti5: That's the modern look
[20:55:02] newdan: smathy: Someone who wants to make sure the process for installing Rails is still the same, maybe
[20:55:12] newdan: I don't see what's confusing about someone going to a website for information
[21:32:58] newdan: Ox0dea: How does that work? That block never gets run?
[21:44:31] newdan: has left #RubyOnRails: ()
[22:22:22] newdan: Remote host closed the connection


[19:24:07] newdan: has joined #ruby
[19:38:39] newdan: newbie22: Python and Ruby should get you plenty of chances. Other languages good for getting into the field are Javascript, Java, PHP, and depending on where you are, C++. Might help to just search want ads and see what people are looking for
[19:45:34] newdan: shevy: Ruby's doing fine
[19:46:48] newdan: JS has the unique advantage of being *the only* choice for running anything in the browser, but supposedly with new tech like WASM that won't last forever
[19:50:06] newdan: zambini: You can try compiling Ruby to JS using Opal
[20:00:15] newdan: shevy: "Learn Ruby the Hard Way" doesn't teach idiomatic Ruby?
[20:07:22] newdan: shevy: Yeah, most people I know wouldn't put in empty parens
[20:20:08] newdan: psuedo: != is more straightforward imo
[21:53:57] newdan: rbenv is the only one that reads the intended Ruby version from the command line, right?
[21:54:05] newdan: Er, meant to say from the filesystem
[21:54:48] newdan: adaedra: Elaborate?
[22:30:44] newdan: Remote host closed the connection


[05:32:39] newdan: has joined #ruby
[05:34:02] newdan: Is there a method to match a regex only at a certain index? E.g. ideally /foo/.strict_match('ofoo', 0) => nil; /foo/.strict_match('ofoo', 1) => MatchData
[06:58:28] newdan: has left #ruby: ()


[22:42:08] newdan: has joined #ruby
[22:44:25] newdan: If I'm in a method and I have an object and I keep calling a method on it like `my_fun_file.my_fancy_write "Hello"`, but I get tired of all that typing, is there a way to alias that to something shorter, in the scope of one method body? And preferably avoiding the `method_obj.('Hello')` syntax?
[22:45:42] newdan: apeiros: Don't even start, I'm using spacemacs
[22:46:03] newdan: Emacs distribution with vim keybindings and, I dunno, in space I guess
[22:46:51] newdan: norc: It does. I can make it appear without typing but it still feels verbose
[22:47:24] newdan: I should've suspected an IRC room would tell me to learn how to type or get a new editor rather than actually answer my question in any way
[22:47:31] newdan: Thanks all
[23:08:49] newdan: Quit: Lost terminal


[01:37:05] newdan: has joined #ruby
[05:47:16] newdan: Quit: leaving


[19:54:07] newdan: has joined #ruby
[19:57:13] newdan: leitz: Use or something
[19:57:19] newdan: leitz: Don't paste code right into IRC
[19:58:23] newdan: Haha thank you Mon_Ouie
[20:01:17] newdan: No need to berate him for not knowing not to paste in IRC. Everyone's new at some point...
[20:03:36] newdan: There's tons, gist is mentioned in the topic and is one I use a lot for some reason
[21:06:26] newdan: leitz: your valid_json? method is real weird conceptually
[21:07:50] newdan: leitz: Usually methods ending with ? return true/false, but yours returns [data, true] *or* raises a ParserError
[21:08:49] newdan: newdan: I would name it maybe something like try_parse_json and have it return [data, true] or [nil, false]
[21:12:01] newdan: leitz: Either let it propagate (meaning don't even bother rescue-ing it if you're just gonna raise it again), or handle it there
[21:12:59] newdan: leitz: Returning [data, true] in one case makes it seem like your method is *meant* to handle invalid data in the bad case, by doing something like returning [nil, false]. But instead it just raises a ParserError, which doesn't buy you anything over just calling JSON.parse directly instead of calling valid_json?
[21:14:14] newdan: In your calling code you still need to begin/rescue JSON::ParserError, so the question then is why use valid_json? instead of JSON.parse?
[21:15:34] newdan: leitz: You don't seem to be handling the ParserError at the call site anyway. So you could probably just delete valid_json? altogether and use JSON.parse directly
[21:22:44] newdan: shevy: I think he means show an error to the user
[21:24:02] newdan: leitz: Oh and I was mistaken when I said you weren't rescuing the error anyway. You are on line 54. So instead of outputting "bang" you can just, say, puts "Error: JSON is invalid"
[21:25:00] newdan: leitz: Although it's generally good to write to STDERR and return a nonzero status code to the OS. #abort does both of those
[21:25:33] newdan: leitz: So on line 55 you can do `abort "JSON is invalid"`
[21:26:06] newdan: leitz: And since you don't use the exception object you might as well turn line 54 into just `rescue JSON::ParserError` (taking away the `=> bang` at the end)
[21:45:49] newdan: leitz: Also don't be afraid to play around with small snippets and methods in irb/pry
[22:21:23] newdan: Remote host closed the connection


[15:20:17] newdan: DylanJ: AFAIK monkey patches are global in scope. New Ruby feature Refinements is supposed to allow it to be localized, but I haven't looked into that myself
[16:24:04] newdan: vnk: Also if you want to call a setter method from another method. x = 3 introduces a new local x, self.x = 3 will call x=() method
[16:24:30] newdan: vnk: Also if you simply want to refer to the current object for any reason in your method. E.g. "return self"
[18:22:10] newdan: has left #ruby: ()