« Back to channel list

#ruby - 01 January 2019

« Back 1 day Forward 1 day »
[00:00:52] laaron: has joined #ruby
[00:04:44] r29v: has joined #ruby
[00:22:20] uplime: has joined #ruby
[00:23:58] johnny56: has joined #ruby
[00:29:09] jottr: has joined #ruby
[00:43:54] m0w: has joined #ruby
[00:43:58] al2o3-cr-tmp: has joined #ruby
[00:57:03] barg: has joined #ruby
[00:57:44] barg: How do I convert a nokogiri object alement into a string.. for example, if I am in IRB, and I do irb(main):159:0> a=doc.css('table')[0].css('tr')[0] then it shows
[00:57:44] barg: => #<Nokogiri::XML::Element:0x3fc15059233c name="tr" children=[#<Noko... If I do. a.to_s then it shows => "<tr><td colspan=\"2\" style=\"text-align:center\"><. Which isn't what I want.. I want that this string "#<Nokogiri::XML::Element:0x3fc15059233c name="tr" children=[#<Noko.." How do I get that string?
[00:59:06] phaul: barg: try #inspect
[01:00:57] laaron-: has joined #ruby
[01:01:18] hutch: has joined #ruby
[01:10:34] phaul: barg? did that give you what you wanted?
[01:13:35] barg: thanks, probably, i have to test it
[01:13:46] barg: i'm going up and downstairs at the moment doing two things at the same time
[01:14:45] phaul: ah :) careful then
[01:16:19] agent_white: has joined #ruby
[01:20:07] barg: phaul: Yes, Thanks!
[01:20:13] barg: that does what I wanted
[01:20:33] havenwood: Loving this experimental feature! https://github.com/ruby/ruby/commit/67c574736912003c377218153f9d3b9c0c96a17b
[01:20:46] havenwood: The :. syntax looks fantastic to me.
[01:23:14] phaul: havenwood: reddit just started discussing that, so far it's not getting much love, but not many ppl responded yet
[01:23:33] uplime: is it like foo.method(:bar) ?
[01:24:48] tdy: has joined #ruby
[01:26:24] al2o3-cr: uplime: yes.
[01:26:25] phaul: not really an operator.
[01:26:50] phaul: nm I deleted what I wanted to send but I left half sentence at the end :)
[01:27:16] uplime: al2o3-cr: thanks
[01:29:47] phaul: Is there a better way to delete what you decide not to say than Ctrl-A Ctrl-K in weechat?
[01:33:27] pabs: try ctrl-u
[01:34:10] phaul: pabs: thanks
[01:36:34] elomatreb: has joined #ruby
[01:43:10] hutch: has joined #ruby
[01:47:38] elomatreb: has joined #ruby
[02:12:16] uplime: phaul: also ctrl+w to delete the last word
[02:13:08] elomatreb: has joined #ruby
[02:14:59] spacesuitdiver: has joined #ruby
[02:36:00] orbyt_: has joined #ruby
[02:41:13] hutch: has joined #ruby
[02:52:07] tdy1: has joined #ruby
[03:01:20] laaron: has joined #ruby
[03:02:07] hutch: has joined #ruby
[03:12:59] hutch: has joined #ruby
[03:22:50] guardianW: has joined #ruby
[03:25:52] kapil____: has joined #ruby
[03:27:21] cschneid: has joined #ruby
[03:30:47] hutch: has joined #ruby
[03:40:38] rkazak: has joined #ruby
[03:41:39] Milos: has joined #ruby
[04:01:07] domgetter: has joined #ruby
[04:01:39] laaron-: has joined #ruby
[04:01:54] domgetter: Is there a way to pipe to irb? e.g. echo -e "hello\nworld" | irb
[04:02:34] domgetter: If I have to do it with something like ruby -r irb -e "require 'irb'" or the like, that's fine too, I just couldn't find any working examples online
[04:09:21] braincrash: has joined #ruby
[04:13:50] houhoulis: has joined #ruby
[04:19:21] nowhere_man: has joined #ruby
[04:27:34] cyberarm: has joined #ruby
[04:31:40] Emmanuel_Chanel: has joined #ruby
[04:36:32] goez: has joined #ruby
[04:37:20] havenwood: domgetter: ruby -e 'binding.irb'
[04:40:01] havenwood: domgetter: ah, pipe to, gotcha
[04:41:00] havenwood: domgetter: sec
[04:42:33] hutch: has joined #ruby
[04:46:40] havenwood: domgetter: I've actually gotta run, but maybe something like: echo "meaning = 42" | ruby -e "eval STDIN.gets; binding.irb"
[04:46:58] havenwood: domgetter: I'll find a way later if that ^ doesn't work.
[04:53:16] jthomas2: has joined #ruby
[05:03:01] laaron: has joined #ruby
[05:17:26] goez: has joined #ruby
[05:18:40] Iambchop: domgetter, havenwood: http://dpaste.com/1Q6GMA0
[05:28:31] Xiti: has joined #ruby
[05:34:53] cnsvc: has joined #ruby
[05:36:33] nowhere_man: has joined #ruby
[05:45:41] Hien: has joined #ruby
[05:56:08] Swyper: has joined #ruby
[05:59:18] elomatreb: has joined #ruby
[06:04:26] Emmanuel_Chanel: has joined #ruby
[06:11:57] elomatreb: has joined #ruby
[06:17:25] ur5us: has joined #ruby
[06:23:38] kapil____: has joined #ruby
[06:40:12] KeyJoo: has joined #ruby
[06:40:44] nowhere_man: has joined #ruby
[06:59:05] jthomas2: has joined #ruby
[07:01:20] laaron-: has joined #ruby
[07:01:52] cschneid: has joined #ruby
[07:05:48] cnsvc: has joined #ruby
[07:09:29] cnsvc_: has joined #ruby
[07:10:58] cnsvc_: anybody works on freebsd & rbenv?
[07:11:12] cnsvc_: had a installation problem with ruby-build
[07:16:47] spacesuitdiver: has joined #ruby
[07:22:21] armyriad: has joined #ruby
[07:22:57] cnsvc_: paste log here: https://clbin.com/1UFUI
[07:25:45] _whitelogger: has joined #ruby
[07:32:10] cschneid: has joined #ruby
[07:45:42] dellavg_: has joined #ruby
[08:01:15] dinfuehr: has joined #ruby
[08:06:43] rippa: has joined #ruby
[08:10:41] dinfuehr: has joined #ruby
[08:13:52] _whitelogger: has joined #ruby
[08:16:03] Fernando-Basso: has joined #ruby
[08:18:06] ur5us: has joined #ruby
[08:21:04] dinfuehr: has joined #ruby
[08:25:33] clemens3: has joined #ruby
[08:32:05] dinfuehr: has joined #ruby
[08:39:40] cschneid: has joined #ruby
[08:45:38] jottr: has joined #ruby
[09:02:47] za1b1tsu: has joined #ruby
[09:09:02] al2o3-cr: has joined #ruby
[09:18:07] al2o3-cr: has joined #ruby
[09:21:27] cnsvc: has joined #ruby
[09:21:28] cnsvc_: has joined #ruby
[09:28:04] sandelius: has joined #ruby
[09:41:27] Pisuke: has joined #ruby
[09:45:43] Nicmavr: has joined #ruby
[09:47:08] dostoyevsky: has joined #ruby
[10:01:48] MasterAsia: has joined #ruby
[10:04:23] sandelius: has joined #ruby
[10:05:19] Dbugger: has joined #ruby
[10:26:27] dostoyevsky: has joined #ruby
[10:32:56] reber: has joined #ruby
[10:34:32] venmx: has joined #ruby
[10:42:50] rippa: has joined #ruby
[10:44:01] cnsvc_: has joined #ruby
[10:44:01] cnsvc: has joined #ruby
[10:46:50] r3m_: has joined #ruby
[10:49:45] Mike111: has joined #ruby
[11:09:29] cschneid: has joined #ruby
[11:12:02] thunderbirdtr: has joined #ruby
[11:15:33] dviola: has joined #ruby
[11:20:37] al2o3-cr: has joined #ruby
[11:24:03] gix: has joined #ruby
[11:30:01] conta: has joined #ruby
[11:30:02] sandelius: has joined #ruby
[11:30:21] sandelius: Happy new year everyone
[11:34:36] up|ime: not everyone! there's still one timezone left in 30 minutes.
[11:34:59] up|ime: but besides those guys, aye.
[11:38:29] sandelius: Yeah that's true, I sometime forget that the world isn't centered around Sweden ^^
[11:38:51] akosednar: has joined #ruby
[11:39:47] jthomas2: has joined #ruby
[11:43:18] up|ime: has it ever been? :P|
[11:49:36] kapil____: has joined #ruby
[11:51:45] cnsvc: has joined #ruby
[11:51:45] cnsvc_: has joined #ruby
[12:10:56] Inline: has joined #ruby
[12:14:24] rippa: has joined #ruby
[12:24:01] mikecmpbll: has joined #ruby
[12:47:51] za1b1tsu: has joined #ruby
[13:27:37] AJA4350: has joined #ruby
[14:12:25] cnsvc_: has joined #ruby
[14:12:25] cnsvc: has joined #ruby
[14:35:03] nfk: has joined #ruby
[14:42:23] x0F: has joined #ruby
[15:00:53] nowhere_man: has joined #ruby
[15:10:52] johnny56: has joined #ruby
[15:13:01] jottr: has joined #ruby
[15:14:11] cnsvc_: has joined #ruby
[15:14:12] cnsvc: has joined #ruby
[15:16:37] sandelius: has joined #ruby
[15:20:54] Xiti: has joined #ruby
[15:21:39] Azure: has joined #ruby
[15:28:44] despai: has joined #ruby
[15:29:16] za1b1tsu: has joined #ruby
[15:34:31] cschneid: has joined #ruby
[15:39:45] lucasb: has joined #ruby
[15:41:27] RougeR: has joined #ruby
[15:45:41] sandelius: has joined #ruby
[15:46:08] ellcs: has joined #ruby
[15:47:08] rkazak: has joined #ruby
[15:49:59] Aqo: has joined #ruby
[15:59:03] houhoulis: has joined #ruby
[16:01:34] roshanavand: has joined #ruby
[16:06:34] dviola: has joined #ruby
[16:10:01] MasterAsia: has joined #ruby
[16:18:15] davidw_: has joined #ruby
[16:31:24] ellcs: has joined #ruby
[16:37:34] rkazak: has joined #ruby
[16:47:49] agent_white: has joined #ruby
[16:50:15] tdy1: has joined #ruby
[16:55:05] havenwood: Iambchop: Nice!
[16:55:36] zapata: has joined #ruby
[16:56:13] uplime: has joined #ruby
[16:59:13] tdy: has joined #ruby
[17:01:06] cnsvc_: has joined #ruby
[17:01:07] cnsvc: has joined #ruby
[17:03:24] BH23: has joined #ruby
[17:04:35] Exagone313: has joined #ruby
[17:15:48] cschneid: has joined #ruby
[17:16:07] reber: has joined #ruby
[17:21:18] clemens3: has joined #ruby
[17:24:32] kapil____: has joined #ruby
[17:30:42] roshanavand: has joined #ruby
[17:32:24] Mike11: has joined #ruby
[17:38:20] Swyper: has joined #ruby
[17:40:34] Swyper: https://dpaste.de/YPsx
[17:41:00] Swyper: &>> 1 == "1"
[17:41:02] rubydoc: # => false (https://carc.in/#/r/5wa0)
[17:41:18] Swyper: does ruby support loose comparisons like js?
[17:43:32] Swyper: if(year[3].to_i == 1 || year[3].to_i == 9 || year[3].to_i == 7) fixed it, but would still like to know the answer to ^
[17:43:49] lupine: nothing quite so insane, but sure, you can define the "==" method for most classes
[17:43:50] lupine: (not all of them)
[17:44:51] Swyper: https://dpaste.de/k2BD
[17:44:57] Swyper: any idea why this test is failing o-o
[17:45:28] dviola: has joined #ruby
[17:46:47] KeyJoo: has joined #ruby
[17:47:51] leftylink: well, you have a REPL at your disposal. you should strongly consider using it to evaluate some useful expressions
[17:48:00] leftylink: for example, what would 'a-z'.include?('x') be?
[17:48:01] havenwood: Swyper: 'a-z' doesn't expand to a range
[17:48:21] Swyper: I don't know what a REPL is, leftylink
[17:48:27] havenwood: ?irb Swyper
[17:48:28] ruby[bot]: Swyper: irb is "interactive ruby", it is part of ruby. You can run ruby code and see results immediately. it's useful for testing code. Also see ?pry, a gem which is a popular alternative to irb.
[17:49:00] Swyper: a-z does expand to a range I thought? hm
[17:49:10] Swyper: &>> "xyz".count("a-z")
[17:49:11] rubydoc: # => 3 (https://carc.in/#/r/5wa1)
[17:49:14] havenwood: Swyper: It'd be a valid glob.
[17:49:27] havenwood: Swyper: #count uses globbing.
[17:49:36] Swyper: &>> "xyzUUUU".count("a-zA-Z")
[17:49:37] rubydoc: # => 7 (https://carc.in/#/r/5wa2)
[17:49:49] havenwood: Swyper: Wherever globs are used, it's good.
[17:49:55] Swyper: whats globbing? or do you prefer I google it xD
[17:50:26] havenwood: Swyper: It's kinda like regex, but simpler. It's what shells use for file matching.
[17:50:49] havenwood: ls *.{exe,etc}
[17:51:10] leftylink: because 'a-z' is a string, to see the behaviour of 'a-z'.include?(whatever) , you would see what String#include? does.
[17:51:20] Swyper: &>> ('a-z').include?("b")
[17:51:21] rubydoc: # => false (https://carc.in/#/r/5wa3)
[17:51:21] leftylink: &ri String#include?
[17:51:22] rubydoc: https://ruby-doc.org/core-2.6/String.html#method-i-include-3F
[17:51:58] havenwood: &>> [*?a..?z]
[17:51:58] rubydoc: # => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", ...check link for more (https://carc.in/#/r/5wa4)
[17:52:25] Swyper: what does the *? and ? do
[17:52:40] rubydoc: # => "a" (https://carc.in/#/r/5wa5)
[17:52:41] havenwood: Swyper: ?a is a character literal for 'a'
[17:52:59] havenwood: Swyper: the * expands the range into its elements
[17:53:27] havenwood: &>> (?a..?z).size
[17:53:28] rubydoc: # => nil (https://carc.in/#/r/5wa6)
[17:53:53] havenwood: &>> [?a..?z].size
[17:53:53] rubydoc: # => 1 (https://carc.in/#/r/5wa7)
[17:53:57] havenwood: &>> [*?a..?z].size
[17:53:57] rubydoc: # => 26 (https://carc.in/#/r/5wa8)
[17:54:56] jhass: I hope ruby 3 will finally drop the ?x syntax
[17:55:31] havenwood: jhass: I doubt it, since it only fell out of favor with 1.8 incompatibility.
[17:56:06] havenwood: ACTION tries to bring ?x back :P
[17:56:19] jhass: wasn't it introduced because String#[] used to return the codepoint?
[17:57:06] havenwood: jhass: yeah, I guess I could see 1.9 change as on the path to deprecation - but I don't think it'll actually be removed
[17:57:30] jhass: too bad, it's just confusing and we shouldn't be perl
[17:57:41] Swyper: so here is what I attempted though I can see how to do it using what you showed me above
[17:57:44] Swyper: ("a-z").split.reject {|char| ("a-z").count(char) > 1 }
[17:57:56] Swyper: err that should be >=
[17:58:03] havenwood: &>> 'a-z'.split
[17:58:03] rubydoc: # => ["a-z"] (https://carc.in/#/r/5wa9)
[17:58:46] havenwood: Swyper: ('a'..'z')
[17:58:57] havenwood: &>> ('a'..'z').count
[17:58:57] rubydoc: # => 26 (https://carc.in/#/r/5wad)
[17:59:11] havenwood: &>> ('a'..'z').class
[17:59:11] rubydoc: # => Range (https://carc.in/#/r/5wae)
[17:59:49] Swyper: thats..pretty confusing why aren't the notations for ranges uniform across Ruby ?
[17:59:49] jthomas2: has joined #ruby
[18:00:21] jhass: they are, ? is just confusing, forget about it
[18:00:26] havenwood: Swyper: Globs are just globs. They only work where globs are expected. They're like a minigame.
[18:00:49] havenwood: Swyper: Ranges are: thing..other_thing
[18:01:16] havenwood: &>> (42..100).count
[18:01:16] rubydoc: # => 59 (https://carc.in/#/r/5wai)
[18:01:31] rubydoc: https://ruby-doc.org/core-2.6/Range.html
[18:02:03] Swyper: jhass: eh I kind of have to learn it for what I'm doing rn
[18:02:15] Swyper: tho I guess you could argue there are different ways to do which don't involve using those concepts :P
[18:02:26] havenwood: to be fair, you could never learn ?x and you'd be finne
[18:02:49] havenwood: i just have an agenda :P
[18:02:59] jhass: ?a == 'a', thus (?a..?z) == ('a'..'z'). the right hand variant is the common one you should remember and use, forget about the ?a stuff
[18:02:59] ruby[bot]: jhass: I don't see no ==, whom should I tell about a?
[18:03:18] Swyper: whats the agenda?
[18:03:23] havenwood: ?cookie ruby[bot]
[18:03:23] ruby[bot]: ruby[bot]: here's your cookie: 🍪
[18:03:36] Swyper: to get a cookie? :P
[18:03:48] Swyper: ('a'..'z').select {|char| ("a-z").count(char) >= 1 } so I'm obviously still messing up the notation somewhere still
[18:03:54] ruby[bot]: jhass: I don't know anything about a
[18:04:26] havenwood: Swyper: ("a-z").count #=> 3
[18:04:30] havenwood: well, #size, but it's only 3
[18:04:34] rkazak: has joined #ruby
[18:05:22] havenwood: Swyper: You can only use globs as an argument when it's expected. You can never use them as a receiver for methods.
[18:05:42] havenwood: Swyper: Don't call methods on a glob. They're just a dump string.
[18:06:05] havenwood: dumb string*
[18:06:24] Swyper: so the generic way to call a range from a-z is ('a'..'z') that will work in most cases?
[18:07:43] havenwood: Swyper: Yes, that's a valid Range of Strings.
[18:08:00] havenwood: &>> ('a'..'z').include? 'm'
[18:08:01] rubydoc: # => true (https://carc.in/#/r/5wax)
[18:08:07] Swyper: expected: ["a", "q", "r", "w"]
[18:08:08] Swyper: got: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
[18:08:10] Swyper: ('a'..'z').select {|char| ('a'..'z').count(char) >= 1 } ->
[18:08:19] Swyper: ignore the ->
[18:08:31] tdy: has joined #ruby
[18:08:33] havenwood: Swyper: How many "m"s are there in ("a".."z")?
[18:08:55] havenwood: Swyper: So how many of char are in?: ('a'..'z').count(char)
[18:09:32] havenwood: Swyper: always 1
[18:09:35] havenwood: Swyper: or 0
[18:09:42] havenwood: Swyper: never > 1
[18:10:02] havenwood: just because our range of letters doesn't include repeats
[18:10:30] Swyper: I got kind of confused because I thought that a string and a character might not evaluate to true 'a' == "a" might be false
[18:10:38] Swyper: &>> 'a' == "a"
[18:10:39] rubydoc: # => true (https://carc.in/#/r/5wb2)
[18:10:46] Swyper: cool guess it does not work that way xD
[18:10:47] havenwood: &was >> ?a == 'a'
[18:11:18] havenwood: Swyper: Just different ways to say the same thing.
[18:11:53] Swyper: expected: ["a", "q", "r", "w"] got: []
[18:12:05] Swyper: ('a'..'z').reject {|char| ('a'..'z').count(char) == 1 }
[18:12:37] havenwood: &>> ('a'..'z').include? 'm'
[18:12:38] rubydoc: # => true (https://carc.in/#/r/5wb5)
[18:12:49] tdy: has joined #ruby
[18:13:15] Swyper: so what this line should be doing is iterating through the list of all characters, and rejected those wherever the count == 1 and sending back a list a-z where none of the elements of the list are elements of the string
[18:13:15] havenwood: Swyper: Checking for inclusion is a bit more straightforward than counting.
[18:13:59] Swyper: jeez my logic here is so bad let me rewrite
[18:14:02] leftylink: regarding "are elements of the string" - then logically, the code should include some reference to the string there.
[18:14:26] havenwood: Swyper: Every character in 'a'..'z' is in 'a'..'z' so it's expected to be empty
[18:14:42] Swyper: ('a'..'z').reject {|char| string.count(char) == 1 }
[18:14:57] leftylink: counterexample: "aardvark"
[18:15:32] Swyper: ('a'..'z').reject {|char| "aardvark".count(char) == 1 }
[18:15:41] Swyper: &>> ('a'..'z').reject {|char| "aardvark".count(char) == 1 }
[18:15:42] rubydoc: # => ["a", "b", "c", "e", "f", "g", "h", "i", "j", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "w", ...check link for more (https://carc.in/#/r/5wb6)
[18:16:46] eam: in rspec I want to validate that the lines in a file either 1) don't have foo, or 2) if they have /foo/ that they also have /bar/
[18:16:56] eam: what's the best approach?
[18:17:57] Swyper: I think using regex in someway if you can but I'm not to good with Ruby xD
[18:17:58] leftylink: I'd do something like `line !~ /bar/ || line =~ /foo` I suppose ?
[18:18:10] leftylink: oh wait, other way around
[18:18:26] eam: it's conditional, so not having either foo or bar is ok
[18:18:33] eam: but if it has foo, it must have bar
[18:18:52] leftylink: `line !~ /foo/ || line =~ /bar/` . I think I'm translating "P implies Q" right this time...
[18:19:45] eam: I can do expect(file).to match(/foo.*bar/) but this doesn't allow for cases where foo isn't present
[18:20:01] eam: do I need to just dump all the rspec syntax and do it in straight ruby?
[18:21:06] leftylink: if it must have some rspec syntax... you could use something like `expect(file.lines).to be_all { |line| line =~ whatever }`
[18:21:35] leftylink: because `be_x` in general becomes `thing.x?`
[18:22:55] eam: ooh, that gives me a block with arbitrary ruby? I can work with that
[18:23:30] eam: I can just say { |line| line !~ /foo/ or line =~ /foo.*bar/
[18:23:35] eam: thanks :)
[18:26:14] havenwood: eam: or the new #match? is faster, since it doesn't set magic variables and such
[18:26:29] havenwood: but there's no #not_a_match? inversion
[18:26:32] eam: I was looking at match, but how do I -- yeah
[18:26:44] eam: and the conditional of match A or B cases
[18:27:12] havenwood: eam: Regexp.union
[18:27:31] eam: what I'm trying to do is write a serverspec spec to ensure that any ext filesystem in /etc/fstab has errors=panic set
[18:28:22] eam: havenwood: that just adds an | right?
[18:28:30] leftylink: the error message for when the `be_all` is violated might be a bit less than ideal since it doesn't tell you exactly which line violated it. I might suggest something like `file.each_line { |line| next if line.include?('ext'); expect(line).to whatever }`
[18:28:44] havenwood: eam: and it saves the end directives mix if any
[18:28:44] eam: https://gist.github.com/eam/c052e46522d2ad10d1bec8dd054d7796
[18:28:50] leftylink: assuming I'm not violating some rspec style recommendations egregiously
[18:30:20] havenwood: a negative lookahead would be an option
[18:31:09] eam: oooh a serverspec file() doesn't have #lines
[18:31:38] havenwood: eam: how about?: /yup(?!nope)/
[18:33:39] eam: I don't think that works because I have .* in between yup and nope
[18:34:01] eam: so the engine is finding a solution where nope is in the wildcard
[18:35:44] cschneid: has joined #ruby
[18:36:02] despai: has joined #ruby
[18:36:34] havenwood: &>> 'yup blah blah nope'.match? /yup.*(?!nope)/
[18:36:34] rubydoc: # => true (https://carc.in/#/r/5wc3)
[18:37:20] havenwood: eam: seems it'd work to me ^, or am I missing something?
[18:37:43] havenwood: yes, I'm missing something
[18:38:06] dostoyevsky: has joined #ruby
[18:38:38] eam: I think I mis-stated the problem too, it's either not /ext/ or /ext.*errors=panic/
[18:40:13] leftylink: maybe it'd make the test clearer anyway to do it in two stages rather than try with one regex
[18:40:24] scrptktty: has joined #ruby
[18:43:00] Swyper: has joined #ruby
[18:49:42] orbyt_: has joined #ruby
[18:51:15] tdy: has joined #ruby
[19:00:36] thunderbirdtr: has joined #ruby
[19:02:08] Swyper: has joined #ruby
[19:02:12] Swyper: https://dpaste.de/4pKc
[19:02:26] Swyper: I can't figure out where my logic is wrong at all
[19:03:07] eam: I ended up with https://gist.github.com/eam/598497d3a688126929dbc1ba687c3b90
[19:04:50] Swyper: havenwood the topic used to say to use gist before right? how come we changed it to dpaste ?
[19:04:53] Swyper: just curious
[19:05:03] uplime: gist now requires an account iirc
[19:05:28] leftylink: huh, haven't seen satisfy before, interesting
[19:06:00] za1b1tsu: has joined #ruby
[19:06:01] Swyper: if (songs[songs.index{song_name}] == songs[(songs.index{song_name})-1] || songs[songs.index{song_name}] == songs[(songs.index{song_name})+1])
[19:06:22] Swyper: this should get all repeat songs, not sure why its still sending me a list back with these songs in them o-o
[19:07:30] tiff: has joined #ruby
[19:08:13] havenwood: Swyper: You might want to consider each_cons(3), but hard to tell from that snippet. Show more code?
[19:08:23] roshanavand: has joined #ruby
[19:08:30] Swyper: https://dpaste.de/4pKc
[19:08:35] Swyper: ^ all the code :P
[19:09:03] jthomas2: has joined #ruby
[19:09:15] uplime: what is the .index{ } syntax?
[19:09:49] leftylink: it's the "always return 0" syntax (sarcasm, but true in this case)
[19:10:05] leftylink: well, perhaps I give too much away
[19:10:08] uplime: oh is it just a normal block?
[19:10:32] leftylink: it is true that Swyper should carefully consider what `["a", "b"].index{"b"}` evaluates to
[19:10:46] leftylink: (and yes it is just a normal block)
[19:10:56] leftylink: with the associated consequences
[19:11:22] Swyper: that would return 1 no? leftylink
[19:11:30] havenwood: Swyper: check it!
[19:11:34] leftylink: you have a REPL at your disposal
[19:12:01] leftylink: that's one of the best things it's to be used for
[19:12:33] havenwood: Swyper: "b" is truthy
[19:12:36] Swyper: I thought it would return the actual index of the element, what use is 0
[19:12:37] havenwood: everything but nil and false are truthy
[19:12:53] havenwood: Swyper: use parens for an argument, instead of squirrely braces for a block
[19:13:11] havenwood: &>> ["a", "b"].index("b")
[19:13:12] rubydoc: # => 1 (https://carc.in/#/r/5wcg)
[19:14:57] Swyper: expected: ["da", "do"]
[19:14:57] Swyper: got: ["da", "da", "do", "la", "la", "la"]
[19:16:21] Swyper: updated line is : if (songs[songs.index{song_name}] == songs[(songs.index(song_name))-1] || songs[songs.index(song_name)] == songs[(songs.index(song_name))+1])
[19:16:55] leftylink: index{song_name}
[19:16:57] Swyper: that should check the element before and after the array, and return false if any of those is is a match
[19:17:24] tdy: has joined #ruby
[19:17:53] Swyper: still broken
[19:17:57] Swyper: ill paste an updated dpaste
[19:19:56] roshanavand: has joined #ruby
[19:20:03] Swyper: https://dpaste.de/PnGG
[19:20:06] despai: has joined #ruby
[19:23:41] Swyper: Rubys so hard
[19:27:16] despai: has joined #ruby
[19:29:15] ellcs: has joined #ruby
[19:32:34] Swyper: any ideas?
[19:33:15] cschneid: has joined #ruby
[19:35:15] leftylink: well, you look at all the ways in which your computed answer differs from the expected answer, and then you tackle them one by one. for example, you see that one_week_wonders returns "di" in the result, when it should. so you figure out why it does that, and fix that
[19:35:33] leftylink: s/when it should/when it should not/
[19:37:37] roshanavand: has joined #ruby
[19:39:08] uplime: is ruby 2.6 officially out yet? or is it still in an rc?
[19:40:03] leftylink: was the radition of releasing on christmases upheld?
[19:40:20] uplime: i saw something was released on christmas!
[19:40:39] leftylink: https://www.ruby-lang.org/en/news/2018/12/25/ruby-2-6-0-released/ yeah
[19:40:53] uplime: (mostly i just want the fancy `Integer "42x", exception: false` stuff)
[19:40:57] uplime: neat, thanks
[19:41:47] hutch: has joined #ruby
[19:42:10] cschneid: has joined #ruby
[19:48:52] Lytol: has joined #ruby
[20:00:38] cnsvc: has joined #ruby
[20:00:38] cnsvc_: has joined #ruby
[20:17:50] MasterAsia: has joined #ruby
[20:19:50] Calinou: that reminds me to update, thanks :)
[20:22:11] garyserj: has joined #ruby
[20:24:15] tdy: has joined #ruby
[20:25:52] Nicmavr: has joined #ruby
[20:28:05] uplime: has joined #ruby
[20:28:55] despai: has joined #ruby
[20:29:43] bmurt: has joined #ruby
[20:30:28] Swyper: has joined #ruby
[20:30:35] Swyper: still working on the same problems
[20:30:37] solocshaw: has joined #ruby
[20:35:44] ogres: has joined #ruby
[20:37:22] hutch: has joined #ruby
[20:39:02] DTZUZO: has joined #ruby
[20:44:37] hiroaki: has joined #ruby
[20:45:26] havenwood: uplime: I wrote a post about that: https://medium.com/square-corner-blog/rubys-new-exception-keyword-arguments-4d5bbb504d37
[20:49:25] up|ime: this name makes me think everything is addressed to me. :(
[20:51:36] up|ime: it's interesting you write it as a keyword rather than the python-choose-arg
[20:51:57] up|ime: i get why they would make it a keyword if the other doesn't exist in ruby, but it'll still feel weird to write to me
[20:56:20] uplime: havenwood: thats where i learned about it actually
[21:00:21] phaul: seems I caused some confusion yesterday by calling 'a-z' a string range as opposed to a normal range. I did not know that it's called a glob, I had to call it something..
[21:00:40] phaul: altough I made the distiction a couple of times
[21:04:36] phaul: jhass: still here?
[21:06:35] Swyper: has joined #ruby
[21:06:47] Swyper: is there a method to remove duplicates of a specific element in an array?
[21:06:59] sandelius: has joined #ruby
[21:07:01] Swyper: uniq! removes all duplicates afaik
[21:07:19] sandelius: "evening" everyone
[21:07:24] havenwood: sandelius: hi!
[21:07:35] phaul: sandelius: evening
[21:08:25] havenwood: Swyper: You could do: group_by(&:itself).map(&:first)
[21:12:56] Swyper: is there another method that's simpler to remove all duplicates of a specific element, or remove all elements with a particular value in an array?
[21:13:41] phaul: second one is easy.. #delete
[21:14:03] Swyper: yeah and delete returns the deleted element so I could just add it back that way xD
[21:15:16] phaul: so you have an Array, and an elem, and you want to remove all but first occurance of elem, I am assuming you need to keep it at original index as well? If not then yeah just add it back..
[21:16:18] Swyper: I don't think its comparing the indexes if it then I will have to try another approach
[21:18:41] Swyper: songs.new((delete("song")))
[21:19:29] havenwood: Swyper: delete("song") #=> "song"
[21:20:22] Swyper: whoops took out the quotes xD
[21:20:37] havenwood: Swyper: But you're not calling #delete on an Array there ^ so it'll be NameError.
[21:21:33] Swyper: so song needs to be an Array
[21:22:44] phaul: Swyper: the receiver of the delete method needs to be an Array.
[21:23:22] phaul: In ruby you have objects then a . sign and then method name. That's how you send a method (or message) to an object
[21:23:45] Swyper: songs.new((delete(song))), songs is an array and song is a string
[21:24:35] Swyper: songs.new((delete("xyz"))), would work but have a variable thats a string would not
[21:24:44] Swyper: I'm probably misunderstanding what everyone is saying >_>
[21:24:50] phaul: let's take that apart. songs is the receiver. new is the method.
[21:25:12] phaul: do you really wish to send the new method to songs? probablly not.
[21:25:17] solocshaw: has joined #ruby
[21:26:24] phaul: usually ppl send the new message to classes to create new objects. When you already have an object, you don't send the new method to it. You can send other methods to it, like delete
[21:28:10] phaul: when you just say a method name on it's own like you did with delete, it will be received by self. Whatever self is in that context.
[21:29:08] Swyper: https://gistpages.com/posts/ruby_arrays_insert_append_length_index_remove <-- I was reading the insert part of that and trying the first thing
[21:29:30] Swyper: I get that the new keyword is probably for instantiating a new object like it is in other languages ;x
[21:30:55] tiff: has joined #ruby
[21:31:03] cschneid: has joined #ruby
[21:32:49] phaul: in ruby everything (mostly) is receiver . method ; even if it doesn't look like it. It's really useful if you think about your methods that way. Who's receving it, and how the receiver handles it. In other words there are no procedures or functions. just methods (aka messages) sent to objects
[21:35:20] Radar: in really weird Ruby it can be things like 1::to_s
[21:35:26] Radar: but that's really not standard at all
[21:35:28] Swyper: okay so I tried this which is still wrong: songs.push(delete(song)) , songs is the the object which I am calling the push method on, the push method is supposed to give me the return value of delete(song)
[21:35:40] al2o3-cr: has joined #ruby
[21:35:48] jottr: has joined #ruby
[21:35:48] Swyper: oh I see now where I am probably going wrong
[21:36:41] Swyper: songs.push(songs.delete(song)) also failed xD
[21:36:51] nfk: has joined #ruby
[21:37:07] phaul: you are on the right track though
[21:37:51] Swyper: a.delete("b") #=> "b", is an example given in the docs for delete
[21:38:04] Swyper: I'm not seeing where m method is going wrong exactly
[21:38:59] Swyper: oof I figured it out
[21:45:04] hutch: has joined #ruby
[21:46:26] garyserj: has joined #ruby
[21:54:52] tiff: has joined #ruby
[22:03:26] armyriad: has joined #ruby
[22:05:28] Swyper: has joined #ruby
[22:14:57] cschneid: has joined #ruby
[22:17:18] hutch: has joined #ruby
[22:22:30] rkazak: has joined #ruby
[22:24:18] barg: I have an array of string names=["bob","tod","john"] Why does the following give an error names.each { |x| puts names[x]+"zzz" } ? it says TypeError: no implicit conversion of String into Integer
[22:28:02] uplime: has joined #ruby
[22:29:36] havenwood: barg: `names` is an Array and `name` is a String.
[22:30:07] barg: names[x] should be a string shouldn't it?
[22:30:16] barg: sure 'asdf' is a string no question about that!
[22:30:21] barg: (And Ihave no string called 'name' ;-)
[22:30:37] leftylink: x successively takes on the values "bob", "tod", and "jon"
[22:30:49] barg: oh but I want x to take on the values 0,1,2
[22:30:50] leftylink: therefore, the block evaluates names["bob"] which will cause the tyep error
[22:31:04] leftylink: well, if you want it to take on the values 0, 1, 2, there's Array#each_index for that
[22:31:14] cschneid: has joined #ruby
[22:32:19] barg: why does this not work [0..2].each { |x| puts names[x]+"zzz" }
[22:32:32] barg: isn't x an integer from that range/array 0..2 ?
[22:32:46] barg: this works [0..2].each { |x| puts names[x] }
[22:32:56] barg: but as soon as I try to concatenate something onto names[x] it fails
[22:33:20] havenwood: barg: What does the error say?
[22:33:50] barg: TypeError: no implicit conversion of String into Array
[22:35:01] havenwood: &>> [] + ''
[22:35:02] rubydoc: # => no implicit conversion of String into Array (TypeError) (https://carc.in/#/r/5wdm)
[22:35:35] barg: but names[x] should not be an array!
[22:35:46] havenwood: barg: But it is!
[22:35:52] barg: names is the array
[22:35:58] cnsvc: has joined #ruby
[22:35:59] cnsvc_: has joined #ruby
[22:36:02] havenwood: barg: Show the code that created `names`?
[22:36:08] leftylink: x takes on the value 0..2, therefore names[0..2] is also an array
[22:36:21] barg: names=["bob","john","tod"]
[22:36:25] leftylink: &>> [0..2].each { |x| puts x }
[22:36:25] rubydoc: # => 0..2 ...check link for more (https://carc.in/#/r/5wdn)
[22:36:55] Iambchop: barg: compare "[0..2].each{|x| p x}" to "(0..2).each{|x| p x}"
[22:37:10] Iambchop: oh, leftylink beat me to it :-)
[22:37:21] leftylink: x takesas in, the block is evaluated *once*, with x = 0..2
[22:37:35] havenwood: barg: 3.times { |x| }
[22:37:46] havenwood: &>> 3.times.to_a
[22:37:47] rubydoc: # => [0, 1, 2] (https://carc.in/#/r/5wdo)
[22:38:20] barg: I was using the wrong brackets!
[22:38:43] barg: I should've used round brackets
[22:40:51] Iambchop: depending on your actual end goal: 3.times is probably better than the range :-), map is probably even better
[22:43:08] barg: well i wasn't trying to be clever ;-)
[22:46:16] havenwood: barg: names.each { |name| puts name }
[22:47:01] havenwood: &>> names.map { |name| name.reverse }
[22:47:02] rubydoc: # => undefined local variable or method `names' for main:Object (NameError) (https://carc.in/#/r/5wdp)
[22:47:02] havenwood: &>> names.map &:reverse
[22:47:03] rubydoc: # => undefined local variable or method `names' for main:Object (NameError) (https://carc.in/#/r/5wdq)
[23:00:39] jthomas2: has joined #ruby
[23:02:14] orbyt_: has joined #ruby
[23:08:01] bmurt: has joined #ruby
[23:19:46] tdy: has joined #ruby
[23:29:07] hutch: has joined #ruby
[23:32:24] houhoulis: has joined #ruby
[23:35:41] spacesuitdiver: has joined #ruby