#ruby - 08 January 2018
« Back 1 day Forward 1 day »
[10:23:32] mitch000001: Hey, I just found something in a Ruby program I have never seen before. There was the use of `?` followed by a character. When looking into the source code of Ruby (parse.y) I found the function `static int parse_qmark(struct parser_params *parser, int space_seen)`. From how I understand it it is some sort of character escaping to parse a charcter without quotes within a Ruby source file. Does someone have any additional information about it
[10:23:32] mitch000001: some documentation of the mentioned syntax elements? I could not find anything within ruby docs.
[10:25:11] mitch000001: Here is the character in question in a ruby program on github: https://github.com/ruby/mspec/blob/master/lib/mspec/utils/options.rb#L45
[10:40:25] Hanmac1: they do it again: https://bugs.ruby-lang.org/issues/14336 "Create new method String#symbol? and deprecate Symbol class"
[10:58:28] mozzarella: mitch000001: https://ruby-doc.org/core-2.5.0/doc/syntax/literals_rdoc.html#label-Strings
[13:18:34] nortega: Greetings, I wanted to ask about an issue I've been running into. When trying to install a new version of the `erubis' gem I get an error: `/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ubygems (LoadError)'
[13:18:54] nortega: I feel like something is wrong, especially since it says that a file called `ubygems' is missing.
[13:24:43] canton7: nortega, looks like a typo in the PKGBUILD: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=ruby-erubis
[13:26:49] canton7: nortega, personally I use gem to manage all gems on by arch linux system, and I don't use pacman at all there
[13:27:03] canton7: 'cos if you mix the two, that way lies pain, and not every gem will be in the aur
[13:27:56] nortega: Actually, I really just use ruby for some vim plugins and tmuxinator, so pretty much all my gems come from the AUR or the repos (unless the AUR uses `gem').
[13:37:18] nortega: Alright, that seems to have fixed it. I posted a comment on the AUR page. Thanks.
[13:41:16] nortega: Hmm, seems the tmuxinator package has a similar issue. Is the `-r' flag a new thing?
[13:51:47] nortega: Well, this is arch, the AUR should expect people to have the bleeding edge versions :P
[14:05:26] mongag: here's the code https://gist.github.com/anonymous/541b62eaa551121f527227d6406bf24b
[14:41:58] yrstrly: why does this code just return 0...arr1.length rather than counting how many elements in each array are equivalent
[14:48:54] ruby[bot]: dminuoso: # => /tmp/execpad-c690920b2671/source-c690920b2671:2: syntax error, unexpected .., expecting &. or :: or ...check link for more (https://eval.in/932160)
[14:49:32] apeiros: and it returns the iterated object because that's what the implementers decided to let it return
[14:55:34] apeiros: !fact add compare equal?, eql?, ==, ===, =~ || equal? tests for identity; eql? tests whether two values are the same hash key or value in a set, == tests with regards to sorting (see <=>), === is for case/when expressions and methods like Enumerable#grep, all?, any?, none? etc.
[14:55:34] ruby[bot]: apeiros: I will remember that compare is equal?, eql?, ==, ===, =~ || equal? tests for identity; eql? tests whether two values are the same hash key or value in a set, == tests with regards to sorting (see <=>), === is for case/when expressions and methods like Enumerable#grep, all?, any?, none? etc
[14:55:42] ruby[bot]: equal?, eql?, ==, ===, =~ || equal? tests for identity; eql? tests whether two values are the same hash key or value in a set, == tests with regards to sorting (see <=>), === is for case/when expressions and methods like Enumerable#grep, all?, any?, none? etc.
[14:58:16] phaul: somewhat related: the other day I tried to define an object where obj != obj to trick Array#include? so it thinks it's not in. (Codewars Kata - don't ask) Interestingly #include? bypasses == even though the documentation explicitly states otherwise
[14:58:37] apeiros: !fact ed compare equal?, eql?, ==, === || https://stackoverflow.com/a/7157051 || equal? is obj identity || eql? is hash key/value in a set equality || == is sorting equality (see <=>) || === is for case/when and methods like Enumerable#grep, all?, any?, none? etc.
[14:58:37] ruby[bot]: apeiros: I stand corrected that compare is equal?, eql?, ==, === || https://stackoverflow.com/a/7157051 || equal? is obj identity || eql? is hash key/value in a set equality || == is sorting equality (see <=>) || === is for case/when and methods like Enumerable#grep, all?, any?, none? etc.
[15:00:09] dminuoso: phaul: As usual the most satisfying answer can be found in the source code directly: https://ruby-doc.org/core-2.5.0/Array.html#method-i-include-3F
[15:01:48] dminuoso: apeiros: I frequently enjoy not having to think about such details in Haskell when requiring Eq is all I need, and any two lists [1,2,3] are considered identical..
[15:02:59] phaul: I got to the same conclusion, I just thought it's interesting that the documentation bothers going into explicit details there
[15:18:38] dminuoso: Using .equal? I would have accepted this, but == should give me some "WhoKnowsError"
[15:20:42] dminuoso: apeiros: Yes, but according to Rice's theorem that's impossible (as it would imply solving the halting problem)
[15:21:50] dminuoso: apeiros: Well I expect == to be generic equality (i.e. two objects being extensionally equivalent)
[15:22:40] dminuoso: apeiros: (And by extensionally equivalent I mean outside of __id__/.equal?/etc.)
[15:22:42] apeiros: it's really ordering equality. whether two objects order the same. as in, in terms of <=>. if that's not possible, it's eql? or equal? semantics.
[15:24:13] apeiros: got a case in core/stdlib which would fail that assumption? (not denying that that might be possible)
[15:24:50] dminuoso: apeiros: The thing is, <=> implies a sensible implementation of == due to partial orders being anti symmetric.
[15:25:24] apeiros: "Equality --- At the Object level, == returns true only if obj and other are the same object."
[15:26:11] apeiros: iff you can implement a sensible <=>, then == should be implemented in terms of <=>
[15:26:41] dminuoso: apeiros: absolutely yes, because if your type (i.e. class) is an order, then its anti symmetric.
[15:26:54] apeiros: in all other cases, == should follow either equal? (see Object#==) or eql? semantics.
[15:27:03] dminuoso: clearly == cant mean "equality based on sorting" because not everything is sortable, but == exists for absolutely everything.
[15:28:09] apeiros: I understand how this can be viewed as an inconsistency and impure. but in practice it IME works quite well.
[15:28:54] dminuoso: apeiros: Right, so its not a clear cut "#== means sorting equality" - it means "some generic equality that is sensible for the type of the object". If your type satisfies the Comparable mixin, then because Comparable implies a partial order, then through the antisymmetric relation you have a notion of "two objects being the same"
[15:29:52] dminuoso: Hah I hit Cmd+3<cr>irb<cr> so rapidly, without realizing that weechat was in my third tab.
[15:31:00] dminuoso: phaul: Those kinds of mishaps cant happen. Everything uses pub key authentication or 1password here. =)
[15:34:03] apeiros: I want: my current model, with the pre-2016 keyboard & touchpad + touchid. plus either a lightning port, or the iphones using usb-c, or the iphones having klinke again
[15:34:10] dminuoso: Though escape you cant at least remap to capslock, and for vi you should be using Control+[ instead anyway.
[15:34:39] apeiros: oh, and of course with unsoldered hard drive and ram, and the option to go beyond 16GB (which I had 5y ago already, ffs)
[15:52:12] garyserj: Is there any way that I can write backslashes without having to escape them? I notice that even with single quotes 'abc\\def' will print abc\def
[15:56:15] apeiros: within code, there's no way to quote a string where you never have to escape a backslash
[15:56:38] ruby[bot]: apeiros: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `' for nil:NilClass
[15:59:45] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `' for nil:NilClass
[15:59:55] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `' for nil:NilClass
[16:04:17] garyserj: If I have a="blah"+'\' then I see I have to double the backslash otherwise I get issues on the next line.
[16:04:40] garyserj: are there any other cases besides \' where i'd have to escape the backslash for it to work?
[18:32:44] duane: i have that working...traveling ruby is claiming that the native pg adapter is not there, but when i switch to a mysql adapter to test...it works just fine
[19:54:58] havenwood: chrisseaton: Or at least I'd have sworn they were, but I can't seem to reproduce it actually.
[19:56:27] ruby[bot]: havenwood: # => 0x210fedb4 is recycled object (RangeError) ...check link for more (https://eval.in/932194)
[19:56:33] havenwood: >> frozen_object_id = ''.freeze.object_id; GC.start; ObjectSpace._id2ref frozen_object_id
[20:12:50] apeiros: havenwood: why'd they be garbage collected? only case I could imagine is if a source file as a whole would be unloaded, no? or a piece of code lexically containing that literal (as in: remove_const or undef etc.)
[20:14:27] chrisseaton: apeiros: string constants at the top level of a file for example - think of all those require statements!
[20:18:09] mgalgs: So I'm sure I'm missing something simple, but does anyone know off-hand why my `bundle info middleman` works but `bundle exec middleman` doesn't?? I've already done a `bundle install`.
[22:41:17] zenspider: how is everyone? what'd I miss? I've been offline and pretty much non-coding over the holidays
[23:11:27] havenwood: zenspider: Ruby 2.5 of course! Well, that and a decade worth of processors have been leaking passwords. >.>
[23:30:26] baweaver: @zenspider: predicate methods using === in 2.5 are a thing: https://medium.com/@baweaver/new-in-enumerable-triple-equals-predicates-c1fcd0eabf6d
[23:40:43] leitz: Interesting. test-unit gives an error if you use the "ruby methods default to the last action" bit.
[23:49:07] leitz: zenspider, this is the error. "career.rb:52: warning: assigned but unused variable - skill_options"
[23:49:08] elim_garak: if im wanting to install rubygems on ubuntu so i can install and use jekyll, do i use my distros package by using apt-get install rubygems ?
[23:49:12] leitz: This is the code. https://github.com/LeamHall/2d6_ogl_chargen/blob/master/lib/career.rb#L50-L56
[23:49:44] leitz: zenspider, if I add a "return skill_options" after line 55, the warning goes away.
[23:50:23] zenspider: leitz: it's a warning and not an error, and it has nothing to do with test_unit... just ruby. You activate it by running with warnings on (`ruby -w` or `$-w = true`) and I recommend it.
[23:51:50] zenspider: because ruby. you just want to return the value. you're not doing anything with the name you're assigning it to
[23:54:00] baweaver: If your 5 line method isn't adequately named enough to show that then there's your issue
[23:55:15] zenspider: leitz: evolution: https://gist.github.com/zenspider/bc7090f4753e940214f7524e5ea5d948
[23:56:16] zenspider: yes: that's what I said in: "fix that code by removing the assignment entirely"
[23:57:20] leitz: Also, to your "MAGIC_VALUES" point, the upp is becoming a hash and the key is non-magical.
[23:58:39] troydm: I know this question might sound dumb but if I have defined class in some module how do I include it in rspec describe for testing so I could reference it by name directly instead of writing Module::Class
[23:59:39] zenspider: so it is just a stand alone module and you need to test it via some instance or something?