« Back to channel list

#ruby - 13 September 2018

« Back 1 day Forward 1 day »
[00:08:00] safetypin: has joined #ruby
[00:08:51] cagomez: has joined #ruby
[00:16:29] TheBloke-: has joined #ruby
[00:20:19] cyberRodent: has joined #ruby
[00:21:09] RougeR: has joined #ruby
[00:39:54] mwlang: has joined #ruby
[00:54:16] Nicmavr: has joined #ruby
[01:05:12] ss_much: has joined #ruby
[01:09:10] _whitelogger: has joined #ruby
[01:09:33] akemot: has joined #ruby
[01:09:56] lxsameer: has joined #ruby
[01:19:05] graphene: has joined #ruby
[01:31:04] herbmillerjr: has joined #ruby
[01:44:35] FastJack: has joined #ruby
[01:49:38] idiocrash: has joined #ruby
[01:51:16] esrse: has joined #ruby
[01:58:30] duderonomy: has joined #ruby
[02:06:26] arescorpio: has joined #ruby
[02:26:00] kotepillar_: has joined #ruby
[02:26:41] weaksauce: has joined #ruby
[02:34:13] bmurt: has joined #ruby
[02:36:59] safetypin: has joined #ruby
[02:47:11] safetypin: has joined #ruby
[02:47:16] kent\n: has joined #ruby
[02:49:11] bmurt: has joined #ruby
[02:53:23] pwnd_nsfw: has joined #ruby
[03:03:38] lektrik: has joined #ruby
[03:05:26] im0nde: has joined #ruby
[03:09:27] braincrash: has joined #ruby
[03:10:46] lxsameer: has joined #ruby
[03:18:24] soulisson: has joined #ruby
[03:19:00] soulisson: Hi. Is there a library in ruby to send and receive netbios/llmnr/mdns requests and responses?
[03:20:30] woodruffw: Resolv::MDNS is part of the stdlib, not familiar with anything for netbios or llmnr though
[03:20:57] soulisson: woodruffw, thank you
[03:27:25] bsamorim: has joined #ruby
[03:27:45] Azure: has joined #ruby
[03:40:02] bsamorim: Guys, I have a nested module Foo::Bar in my code. If I load my app, calling Foo::Bar.constants doesn't show me Foo::Bar's classes, but I can successfully invoke all its classes in the same scope
[03:42:21] bsamorim: What could be causing it? The app is loaded by invoking "irb -r /path/to/base_file.rb"
[03:46:36] Freshnuts: has joined #ruby
[03:48:23] ventures: has joined #ruby
[03:49:11] ventures: evening folks, so if I have an existing ruby app, and I want to integrate oh, a user voting system (ala reddits) to an app where all my data is stored in ActiveRecord
[03:49:28] kotepillar_: has joined #ruby
[03:49:34] ventures: what would be the safest cleverest way to go about it
[03:49:41] ventures: in making it a useful ranking system
[03:49:49] bsamorim: ventures: rewriting the whole thing in python
[03:50:01] ventures: I don’t like ruby but I’m not rewriting mastodon
[03:50:29] ventures: I don’t much care for mastodon’s layout and internationalization and I’d be happy if they accept the changes I’m gonna make but, they will be drastic
[03:51:05] kotepillar_: has joined #ruby
[03:51:09] ventures: it seems easy enough to work on, I also am doing a lot of Elixir now so ruby is no big deal. though personally I would not have pulled it as a weapon of choice
[03:51:15] RougeR: has joined #ruby
[03:51:29] ventures: oh wait i’m in #ruby.. sorry guys
[03:51:34] ventures: DSL’s are beautiful!
[03:52:01] bsamorim: i guess that Ruby is one of those languages that can yield very bad code if abused
[03:52:20] ventures: anyway any thoughts on a reddit like system? I guess I don’t really need to segregate by date unless I’m sorting by votes
[03:52:47] bsamorim: what do you mean by "integrating"?
[03:52:58] bsamorim: How would their interaction go about?
[03:54:05] DTZUZO: has joined #ruby
[04:08:22] orbyt_: has joined #ruby
[04:14:16] BTRE: has joined #ruby
[04:23:03] hays_: has joined #ruby
[04:23:44] hays_: i was wondering what people think of this pattern: https://bpaste.net/show/cec01c8f1a04 I am using a class variable which is usually a no-no
[04:24:01] hays_: but it seems right, since i actually do want the variable to inherit to subclasses
[04:25:33] pwnd_nsfw: Why would you have to use a class variable?
[04:26:12] pwnd_nsfw: attr_accessor?
[04:26:12] hays_: how would you do it
[04:26:36] pwnd_nsfw: does that not inherit?
[04:27:10] hays_: i want do be able to do Point.handler_map(:int16).new
[04:27:50] pwnd_nsfw: As opposed to Point.new.handler_map(:int16)?
[04:27:52] hays_: allowing me to avoid a large case statement
[04:28:34] hays_: do you mean Point.new.handler_map(:int16).new ?
[04:28:44] hays_: that seems inefficient
[04:29:03] pwnd_nsfw: I have nfi what you're doing at this point
[04:29:34] hays_: creating a PointINT16 object
[04:29:57] hays_: based on having a variable with :int16 in it
[04:30:46] hays_: without case variable; when :int16; foo=PointINT16.new; when :int32, etc. etc.
[04:31:38] eckhardt: has joined #ruby
[04:31:42] pwnd_nsfw: Seems incredibly redundant, at least with this example, to even have different classes
[04:31:57] pwnd_nsfw: I'm sure a more mature example may shed light on that, but currently it doesn't make sense
[04:32:13] pwnd_nsfw: Could just stick with type attribute in Point object
[04:36:10] hays_: https://bpaste.net/show/bf75fb02e3fe
[04:36:52] hays_: I am obviously not showing the implementation, but these classes all have different details of hows things need to be handled
[04:37:20] hays_: definitely looking for a better way
[04:38:52] pwnd_nsfw: Do you have more items to add to that switch? If not, then that's not really all that bad
[04:39:36] hays_: there are short and long floats, 8 bit variants as well, and possibly others
[04:39:53] hays_: but even that case statement right there is long enough to flag a tool like rubocop
[04:40:30] hays_: plus, that case statement ends up getting copy/pasted to a lot of places since it is outside the class definition
[04:47:21] idiocrash: has joined #ruby
[04:53:58] baweaver: Is there any specific thing those classes do that necessitates a class?
[04:54:54] baweaver: Point.new(:int16) # initialize(type) @type = type
[04:56:44] hays_: there are read and write methods that do very different things
[04:57:14] hays_: when structured like that ^ you end up with big complex methods with a high ABC score
[04:57:50] hays_: those case statements end up in the read/write methods
[04:57:56] baweaver: So move the case branching up to class abstractions
[04:58:28] baweaver: Fair. As far as how to do that, why not namespace?
[04:58:37] hays_: i think that's what im doing?
[04:58:54] hays_: not namespace, but class abstractions
[04:58:54] baweaver: module Point; class Base
[04:59:20] baweaver: then you can just constant get and say something like Point[:uint16].new
[05:01:12] baweaver: module Point; def self.[](type) const_get(type.upcase)
[05:01:19] baweaver: something kinda vaguely like that
[05:02:30] baweaver: Though that's, to be fair, one of the problems I can never get a good answer for.
[05:03:14] hays_: i don't know enough ruby to quite understand how to implement Point[:uint16].new
[05:03:34] baweaver: Lemme screw around with something real quick
[05:03:53] hays_: im screwing around too. with maybe a factory pattern
[05:05:58] hays_: something like this maybe https://bpaste.net/show/39a1bc37d463
[05:06:01] baweaver: https://repl.it/@baweaver/CurvySlimyRelationaldatabase
[05:07:46] hays_: hmm ok that gives me something to think about
[05:12:37] reber: has joined #ruby
[05:13:33] hays_: that's .. interesting. const_get
[05:14:21] hays_: class with a k--is that a convention of some kind
[05:14:55] baweaver: class is a reserved word, so whenever referring to something that could turn into class somehow I tend to use k instead of c
[05:15:13] baweaver: I've seen two types, klass and clazz
[05:15:31] baweaver: klass has been far more common in general around meta-programming
[05:16:36] hays_: i sometimes use cls
[05:16:50] hays_: that's probably a bit terse
[05:17:07] baweaver: in general Ruby spells things out
[05:17:53] hays_: yeah. well thanks for that. I would have never thought to use modules in that way
[05:17:56] baweaver: Which I tend to prefer, especially after reading Haskell where they insist on x:xs and names like that
[05:18:26] hays_: long names are nice, but sometimes cause me grief regarding the 80 line limits
[05:18:40] baweaver: (everyone ignores that)
[05:18:49] baweaver: 100 is more common
[05:19:18] hays_: its always interesting when you have a chain of methods, how far to take it
[05:19:32] baweaver: mm, I use two space line breaks
[05:20:08] hays_: do you mean \
[05:20:19] baweaver: https://dpaste.de/xuqF
[05:24:28] dellavg_: has joined #ruby
[05:25:58] Mike11: has joined #ruby
[05:27:07] hays_: has joined #ruby
[05:27:20] hays_: hotel wifi. erg
[05:28:06] hays_: how do you speak self.[]
[05:28:27] hays_: "self braces" ?
[05:28:32] baweaver: bracket accessor?
[05:29:01] baweaver: That's a good question
[05:29:04] hays_: what about []=
[05:29:17] baweaver: bracket setter?
[05:29:22] baweaver: Never thought about either
[05:29:24] hays_: i was trying to explain to someone what these were
[05:30:02] baweaver: apeiros / havenwood: what do you two call em?
[05:35:14] kapil___: has joined #ruby
[05:35:46] sauvin: has joined #ruby
[05:37:13] scottj: has joined #ruby
[05:37:28] duderonomy: has joined #ruby
[05:39:36] lytol_: has joined #ruby
[05:47:58] siaw23: has joined #ruby
[05:50:44] duderonomy: has joined #ruby
[05:58:45] xfbs: has joined #ruby
[05:59:35] kotepillar_: has joined #ruby
[06:08:23] kotepillar_: has joined #ruby
[06:08:39] LiftLeft2: has joined #ruby
[06:13:12] za1b1tsu: has joined #ruby
[06:16:19] MoritaShinobu: has joined #ruby
[06:16:43] duderonomy: has joined #ruby
[06:24:56] ZzZombo: has joined #ruby
[06:25:13] ZzZombo: Anybody to help me yet?
[06:27:21] armyriad: has joined #ruby
[06:37:38] duderonomy: has joined #ruby
[06:44:56] clemens3_: has joined #ruby
[06:45:13] za1b1tsu: has joined #ruby
[06:47:29] aufi: has joined #ruby
[07:02:30] duderonomy: has joined #ruby
[07:09:13] sameerynho: has joined #ruby
[07:17:20] duderonomy: has joined #ruby
[07:19:02] duderonomy: has joined #ruby
[07:19:25] yohji: has joined #ruby
[07:38:21] nowhere_man: has joined #ruby
[07:50:41] cschneid_: has joined #ruby
[07:53:02] DTZUZO: has joined #ruby
[07:55:08] graphene: has joined #ruby
[07:59:34] Freshnuts: has joined #ruby
[08:01:25] lxsameer: has joined #ruby
[08:10:08] RougeR: has joined #ruby
[08:17:28] graphene: has joined #ruby
[08:21:00] cabotto: has joined #ruby
[08:36:22] RougeR: has joined #ruby
[08:43:11] TomyWork: has joined #ruby
[08:47:11] lyr: has joined #ruby
[08:48:43] Beams: has joined #ruby
[08:50:54] pabs: has joined #ruby
[08:59:02] ur5us: has joined #ruby
[09:12:20] lyr: has joined #ruby
[09:18:11] bomb: has joined #ruby
[09:19:27] graphene: has joined #ruby
[09:19:46] jottr: has joined #ruby
[09:21:58] yohji: has joined #ruby
[09:43:40] za1b1tsu: has joined #ruby
[09:46:06] zxq2: how are you supposed to know what methods generate what exceptions? in mnay cases the documentation sucks
[09:49:51] jottr: has joined #ruby
[09:53:46] za1b1tsu: has joined #ruby
[09:55:38] kapil___: has joined #ruby
[09:57:47] govg: has joined #ruby
[10:23:24] jottr: has joined #ruby
[10:25:24] tristanp: has joined #ruby
[10:46:11] discopatrick: has joined #ruby
[11:00:03] chichou: has joined #ruby
[11:17:07] ur5us: has joined #ruby
[11:25:24] charlielor: has joined #ruby
[11:27:31] xall: has joined #ruby
[11:34:47] jottr: has joined #ruby
[11:41:36] kotepillar_: has joined #ruby
[11:44:30] ZzZombo: has joined #ruby
[11:48:36] AndreYuhai: has joined #ruby
[11:51:17] AndreYuhai: Hi, I have a JSON string from Instagram's page and I've created a class for that. https://dpaste.de/UvYE
[11:51:41] AndreYuhai: But I would like to create an "is_video?" method.
[11:52:11] AndreYuhai: But just on the returned objects from [ ] square brackets
[11:52:36] AndreYuhai: For example: "some_json_obj[1].is_video?" How could I make this work ?
[11:56:18] AndreYuhai: Guess I would have to create a class for edge objects too and then put the method there.
[11:59:05] yohji: has joined #ruby
[12:01:21] thy0: has joined #ruby
[12:09:26] jcalla: has joined #ruby
[12:24:22] za1b1tsu: has joined #ruby
[12:28:04] bmurt: has joined #ruby
[12:33:51] jottr: has joined #ruby
[12:36:00] dviola: has joined #ruby
[12:36:47] impermanence: has joined #ruby
[12:38:03] AJA4350: has joined #ruby
[12:47:59] akem: has joined #ruby
[12:48:06] knight33: has joined #ruby
[12:51:57] akem: has joined #ruby
[13:00:09] herbmillerjr: has joined #ruby
[13:05:06] gnufied: has joined #ruby
[13:12:56] gnufied: has joined #ruby
[13:18:16] jottr: has joined #ruby
[13:22:19] yohji: has joined #ruby
[13:40:24] desperek: has joined #ruby
[13:42:05] Inline: has joined #ruby
[13:43:33] Inline: has joined #ruby
[13:45:49] InfinityFye: has joined #ruby
[13:45:57] nowhere_man: has joined #ruby
[14:06:31] sdegutis: has joined #ruby
[14:08:29] sdegutis: Hi, is there a method in the stdlib that "groups" a flat array by a given function? For example [0,1,2,3,4,5,6].something{|n| n % 3 == 0 } would become [[0,1,2], [3,4,5], [6]]
[14:09:22] NL3limin4t0r: sdegutis: http://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-group_by
[14:09:38] sdegutis: NL3limin4t0r: that is close, but that removes the order which I'm hoping to keep
[14:10:17] sdegutis: Actually that's not close, it returns a different shape than I'm looking for.
[14:10:31] NL3limin4t0r: Never mind, I thought you wanted to group.
[14:10:46] NL3limin4t0r: There is another method that does what you want.
[14:10:49] NL3limin4t0r: Give me a sec
[14:10:50] havenwood: sdegutis: chaunk
[14:10:54] havenwood: chunk*, heh
[14:11:00] havenwood: ACTION searches for coffee
[14:11:02] sdegutis: What I'm looking for would begin a new group when f(n) is true, and keep adding to the group as long as its false.
[14:11:40] sdegutis: chunk is closer, in fact I just used it for a similar problem 2 seconds before this one, but it doesn't keep them together
[14:11:50] havenwood: sdegutis: https://docs.ruby-lang.org/en/2.5.0/Enumerable.html#method-i-chunk
[14:11:51] sdegutis: Is there a Ruby evaluator in here?
[14:12:04] sdegutis: Chunk gives me [[true, [0]], [false, [1, 2]], [true, [3]], [false, [4, 5]], [true, [6]]]
[14:12:14] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[14:12:37] sdegutis: But then I'd need to combine every 2 groups into one.
[14:13:14] NL3limin4t0r: Seems like you just want to slice them in parts of 3.
[14:13:30] NL3limin4t0r: >> [0,1,2,3,4,5,6].each_slice(3)
[14:13:31] ruby[bot]: NL3limin4t0r: # => #<Enumerator: [0, 1, 2, 3, 4, 5, 6]:each_slice(3)> (https://eval.in/1057194)
[14:13:35] NL3limin4t0r: >> [0,1,2,3,4,5,6].each_slice(3).to_a
[14:13:35] sdegutis: NL3limin4t0r: for that given function yeah but in real life it's {|s|s.start_with? 'module '}
[14:13:36] ruby[bot]: NL3limin4t0r: # => [[0, 1, 2], [3, 4, 5], [6]] (https://eval.in/1057195)
[14:15:10] havenwood: sdegutis: The expected output you're showing doesn't line up with modulo 3 being zero. Are you trying to flip-flop on the change of state?
[14:15:19] havenwood: [0,1,2,3,4,5,6].chunk { |n| n % 3 == 0 }.map(&:last) #=> [[0], [1, 2], [3], [4, 5], [6]]
[14:15:35] havenwood: sdegutis: ^ that's the expected output for the block: n % 3 == 0
[14:15:36] sdegutis: I'll combine .chunk and .each_slice(2) to get this done, that'll work fine.
[14:16:08] havenwood: sdegutis: Ah, so it's alternating and you want two chunks?
[14:16:09] havenwood: sdegutis: You might be able to express that also with #chunk_while
[14:16:19] NL3limin4t0r: >> (0..6).slice_before { |n| n % 3 == 0 }.to_a
[14:16:25] ruby[bot]: NL3limin4t0r: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[14:16:45] NL3limin4t0r: >> [0,1,2,3,4,5,6].slice_before { |n| n % 3 == 0 }.to_a
[14:16:46] ruby[bot]: NL3limin4t0r: # => [[0, 1, 2], [3, 4, 5], [6]] (https://eval.in/1057199)
[14:17:02] havenwood: NL3limin4t0r: nice
[14:17:13] NL3limin4t0r: http://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-slice_before
[14:17:16] sdegutis: havenwood: in real life I've got an array of documentation strings where every once in a while one starts with 'module ' and I want to group all the ones afterward with that since they belong to that module
[14:17:51] sdegutis: havenwood: the reason for .each_slice(2) is because .chunk gives me [[true, ['module Foo']], [false, [doc_strings...], ...]
[14:17:54] sdegutis: In that pattern.
[14:18:50] NL3limin4t0r: sdegutis: Does #slice_before fit your issue?
[14:19:07] sdegutis: It looks like it!
[14:19:20] sdegutis: Wow NL3limin4t0r perfect.
[14:19:48] graphene: has joined #ruby
[14:20:16] sdegutis: NL3limin4t0r, havenwood: this is what I have so far thanks to you guys https://gist.github.com/sdegutis/41094989d41cdcd8fc0459785a3a868f
[14:20:37] arup_r: has joined #ruby
[14:22:25] NL3limin4t0r: #map followed by #flatten (flattens recursively) can often be replaced by #flat_map (flattens only one level)
[14:22:43] NL3limin4t0r: http://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-flat_map
[14:22:57] havenwood: +1 flat_map
[14:23:33] thejs: has joined #ruby
[14:23:36] havenwood: it is a flatten(1), not a flatten, fwiw
[14:23:51] havenwood: (which should be fine here)
[14:24:17] havenwood: sdegutis: nice
[14:25:30] Stan: has joined #ruby
[14:26:07] sdegutis: How do you pass a regular "function" (method defined in root of file) to foo.map ?
[14:27:35] havenwood: sdegutis: by root of file, do you mean top level in Ruby or something else?
[14:29:00] sdegutis: havenwood: I'm inside a .map{} in that block and I'm going to write .map{} inside that other map, and I'm trying to avoid defining the inner mapping method there
[14:29:12] sdegutis: So I'm putting it at the top level of the file, but now I forgot how to pass it.
[14:29:18] sdegutis: I haven't done Ruby professionally in like 6 years.
[14:30:17] NL3limin4t0r: So the this `.map { |e| some_method(e) }` can be replaced by `.map(&method(:some_method))`.
[14:30:26] NL3limin4t0r: I guess that's what you mean.
[14:31:06] sdegutis: Thanks NL3limin4t0r.
[14:31:51] NL3limin4t0r: You can also do that for instance methods if you ever need to.
[14:32:10] havenwood: I like the new syntax for that that's been proposed for that: .map(&.:some_method)
[14:32:19] sdegutis: Yeah I've done it with &:foo in the past on instance methods
[14:32:31] NL3limin4t0r: >> str = 'a'; %w[s d f a k e a].map(&str.method(:==))
[14:32:32] ruby[bot]: NL3limin4t0r: # => [false, false, false, true, false, false, true] (https://eval.in/1057205)
[14:32:56] sdegutis: I've fallen out of love with Ruby years ago but it is handy in situations like this.
[14:35:07] sdegutis: I just had to type def tmod((name, *docs)) to do destructuring. Neat.
[14:46:25] ZzZombo: has joined #ruby
[14:48:53] charlielor: has joined #ruby
[14:54:33] gr33n7007h: has joined #ruby
[14:55:29] rikkipitt: has joined #ruby
[14:56:28] sdegutis: havenwood, NL3limin4t0r: thanks to you guys it only took 38 lines :D https://gist.github.com/sdegutis/a4b6b94a0f07d87ab85b0d7ee3ff65c1
[15:06:44] sdegutis: has left #ruby: ()
[15:08:34] brandoncc: has joined #ruby
[15:15:22] jottr: has joined #ruby
[15:16:21] za1b1tsu: has joined #ruby
[15:16:51] akemot: has joined #ruby
[15:22:15] yohji: has joined #ruby
[15:23:02] knight33: has joined #ruby
[15:24:55] jottr: has joined #ruby
[15:26:30] conta1: has joined #ruby
[15:32:26] rippa: has joined #ruby
[15:33:14] graphene: has joined #ruby
[15:37:07] chouhoulis: has joined #ruby
[15:40:05] Pisuke: has joined #ruby
[15:45:12] beowuff: has joined #ruby
[15:46:38] ivanskie: has joined #ruby
[15:53:00] conta1: has joined #ruby
[15:58:05] bmurt: has joined #ruby
[16:00:23] cagomez: has joined #ruby
[16:01:35] Dbugger: has joined #ruby
[16:08:44] marz_d`ghostman: has joined #ruby
[16:09:12] marz_d`ghostman: Why can I declare a module, a method inside it and invoke the inject(:+) method directly? I though I need to include Enumerable first?
[16:10:54] lxsameer: has joined #ruby
[16:12:41] thejs: has joined #ruby
[16:14:00] jcarl43: has joined #ruby
[16:20:35] [Butch]: has joined #ruby
[16:20:51] lxsameer: has joined #ruby
[16:24:07] aupadhye: has joined #ruby
[16:25:11] brandoncc: has joined #ruby
[16:28:25] charlielor: has joined #ruby
[16:30:56] lxsameer: has joined #ruby
[16:41:07] lxsameer: has joined #ruby
[16:50:51] lxsameer: has joined #ruby
[16:53:27] redlegion: has joined #ruby
[16:58:49] orbyt_: has joined #ruby
[17:01:06] lxsameer: has joined #ruby
[17:11:04] arup_r: has joined #ruby
[17:11:06] lxsameer: has joined #ruby
[17:13:24] RougeR: has joined #ruby
[17:19:03] apeiros: marz_d`ghostman: don't know what you mean. can you gist actual reproducible code?
[17:20:52] lxsameer: has joined #ruby
[17:25:30] eckhardt: has joined #ruby
[17:31:02] lxsameer: has joined #ruby
[17:31:06] Cthulu201: has joined #ruby
[17:32:57] akem: has joined #ruby
[17:35:19] krawchyk: has joined #ruby
[17:36:49] za1b1tsu: has joined #ruby
[17:40:01] arup_r: has joined #ruby
[17:40:55] lxsameer: has joined #ruby
[17:41:43] za1b1tsu: has joined #ruby
[17:48:43] GodFather_: has joined #ruby
[17:49:23] krawchyk: has joined #ruby
[17:49:52] sagax: has joined #ruby
[17:50:08] duderonomy: has joined #ruby
[17:51:01] lxsameer: has joined #ruby
[17:57:19] charlielor: has joined #ruby
[18:00:41] ivanskie: has joined #ruby
[18:01:02] lxsameer: has joined #ruby
[18:04:09] RougeR: has joined #ruby
[18:04:25] bmurt: has joined #ruby
[18:04:28] jottr: has joined #ruby
[18:05:26] orbyt_: has joined #ruby
[18:06:30] samort7: has joined #ruby
[18:07:16] armyriad: has joined #ruby
[18:11:04] lxsameer: has joined #ruby
[18:19:59] wolfshappen: has joined #ruby
[18:20:46] lxsameer: has joined #ruby
[18:21:17] SeepingN: has joined #ruby
[18:29:13] akem: has joined #ruby
[18:30:03] sameerynho: has joined #ruby
[18:30:07] LiftLeft: has joined #ruby
[18:30:52] lxsameer: has joined #ruby
[18:40:58] lxsameer: has joined #ruby
[18:51:07] lxsameer: has joined #ruby
[18:55:21] charlielor: has joined #ruby
[18:58:45] charlielor: has joined #ruby
[18:59:12] orbyt_: has joined #ruby
[19:00:46] lxsameer: has joined #ruby
[19:04:37] th1nkpad: has joined #ruby
[19:04:55] dan64: has joined #ruby
[19:21:59] tdy: has joined #ruby
[19:33:26] charlielor: has joined #ruby
[19:42:20] thy0: has joined #ruby
[19:45:28] DTZUZO: has joined #ruby
[19:46:00] orbyt_: has joined #ruby
[19:51:21] jottr: has joined #ruby
[20:04:22] thejs: has joined #ruby
[20:26:09] dorian: has joined #ruby
[20:32:46] graphene: has joined #ruby
[20:35:52] Azure|dc: has joined #ruby
[20:37:16] dorian: question about circular references: do i have to manage them manually or no?
[20:37:19] code_zombie: has joined #ruby
[20:38:15] DTZUZO: has joined #ruby
[20:39:05] sanscoeur: has joined #ruby
[20:44:29] DTZUZO: has joined #ruby
[20:44:39] leah2: no, ruby's gc handles them fine
[20:46:11] cagomez: has joined #ruby
[20:47:13] dorian: leah2: how far back does that go?
[20:47:30] dorian: (not that i have to support it; just for my own edification)
[20:48:03] apeiros: dorian: I wouldn't be surprised if it went back to the original ruby
[20:48:19] apeiros: given that afaik ruby started out with a mark & sweep gc, which has no issues with circular refs.
[20:48:37] leah2: dorian: since always
[20:48:45] dorian: good to know
[20:48:52] dorian: ACTION inured to perl Scalar::Util::weaken
[20:49:10] \void: has joined #ruby
[20:51:05] apeiros: it's been 2 decades since I did perl, so no idea what that's supposed to mean
[20:52:01] dorian: it's a thing you have to do to decrement the reference count of a data object so it gets properly GC'd
[20:52:30] dorian: (if circular, that is)
[20:52:36] dorian: anyway no bother
[20:54:11] apeiros: perl uses a counting gc?
[20:57:55] dorian: yeah there was talk of moving to mark and sweep a while back but i think they gave up on that
[20:59:52] dorian: ("a while back" being like 15 years)
[21:04:39] lxsameer: has joined #ruby
[21:05:31] croberts: has joined #ruby
[21:06:42] tdy: has joined #ruby
[21:07:15] chouhoulis: has joined #ruby
[21:10:10] mustmodify: has joined #ruby
[21:16:24] za1b1tsu: has joined #ruby
[21:17:24] g-: has joined #ruby
[21:17:59] chouhoulis: has joined #ruby
[21:19:19] chouhoulis: has joined #ruby
[21:22:48] leitz: has joined #ruby
[21:24:29] chouhoulis: has joined #ruby
[21:27:43] graphene: has joined #ruby
[21:29:55] chouhoulis: has joined #ruby
[21:31:21] leitz: Confused on why the tests pass but the program fails. In theory the offending include should be tested, right? https://gist.github.com/LeamHall/f6181aed2d0a1ce26114af399ebee448
[21:31:41] orbyt_: has joined #ruby
[21:34:50] orbyt_: has joined #ruby
[21:35:21] chouhoulis: has joined #ruby
[21:47:13] chouhoulis: has joined #ruby
[21:52:12] jottr: has joined #ruby
[21:52:41] chouhoulis: has joined #ruby
[21:54:11] orbyt_: has joined #ruby
[22:00:12] ivanskie: has joined #ruby
[22:00:55] tdy: has joined #ruby
[22:01:10] graphene: has joined #ruby
[22:03:35] chouhoulis: has joined #ruby
[22:04:21] ciro: has joined #ruby
[22:07:47] pabloh: has joined #ruby
[22:10:04] chouhoulis: has joined #ruby
[22:10:07] za1b1tsu: has joined #ruby
[22:14:16] Nicmavr: has joined #ruby
[22:16:34] chouhoulis: has joined #ruby
[22:20:40] snickers: has joined #ruby
[22:22:03] chouhoulis: has joined #ruby
[22:24:24] nickjj: has joined #ruby
[22:26:15] leitz: Sooner or later I have to figure out the circular loading issue.
[22:26:26] leitz: But the program works, again. Finally!
[22:26:44] mustmodify: has left #ruby: ()
[22:27:29] chouhoulis: has joined #ruby
[22:32:51] chouhoulis: has joined #ruby
[22:38:24] chouhoulis: has joined #ruby
[22:40:36] ellcs: has joined #ruby
[22:44:43] chouhoulis: has joined #ruby
[22:47:53] ramfjord: has joined #ruby
[22:47:57] postmodern: has joined #ruby
[22:48:07] Azure: has joined #ruby
[22:50:07] chouhoulis: has joined #ruby
[22:53:32] nowhere_man: has joined #ruby
[22:57:08] sanscoeur: has joined #ruby
[23:01:03] chouhoulis: has joined #ruby
[23:02:52] tdy: has joined #ruby
[23:04:13] Azure: has joined #ruby
[23:05:19] lxsameer: has joined #ruby
[23:06:27] chouhoulis: has joined #ruby
[23:11:49] chouhoulis: has joined #ruby
[23:15:09] gix: has joined #ruby
[23:17:14] chouhoulis: has joined #ruby
[23:18:27] fredlinhares: has joined #ruby
[23:20:54] sticaz: has joined #ruby
[23:22:29] eckhardt: has joined #ruby
[23:22:41] chouhoulis: has joined #ruby
[23:28:12] chouhoulis: has joined #ruby
[23:33:32] chouhoulis: has joined #ruby
[23:35:49] spiette: has joined #ruby
[23:36:13] eckhardt: has joined #ruby
[23:37:05] mememeIAMMEE: has joined #ruby
[23:38:35] mememeIAMMEE: How do I add values to an existing hash key, accessing the key via string like this, a = 'hashKey'; hash[a] << 98;
[23:38:59] chouhoulis: has joined #ruby
[23:41:43] havenwood: mememeIAMMEE: Are you trying to mutate the `a` local variable by shoveling on a `"b"` string so `a == "hashKeyb"`?
[23:42:00] havenwood: mememeIAMMEE: There is a Hash#rehash method, but it's advised not to mutate Hash keys.
[23:43:09] mememeIAMMEE: Say hashKey[:"myKey"] == [0, 1, 2]
[23:43:14] mememeIAMMEE: All I want to do is
[23:43:52] havenwood: mememeIAMMEE: An aside, but: :"myKey" == :myKey
[23:44:12] havenwood: mememeIAMMEE: Use :snake_case instead of :headlessCamelCase for symbols
[23:44:16] mememeIAMMEE: g = "myKey"; myHash[g] << 3; to make myHash[:"myKey"] == [0, 1, 2, 3]
[23:44:22] chouhoulis: has joined #ruby
[23:44:46] mememeIAMMEE: I come from C#, sorry lol.
[23:46:16] Zarthus: you can do `g.to_sym` or `g = :my_key`
[23:46:17] havenwood: >> g = 'my key'; my_hash = {g => '4'}; my_hash[g] << '2'; my_hash # mememeIAMMEE, so this is the base Hash setup?
[23:46:23] mememeIAMMEE: So you can't shovel values into a hash like you do an array? a << b
[23:46:28] havenwood: #=> {"my key"=>"42"}
[23:46:28] ruby[bot]: havenwood: # => {"my key"=>"42"} (https://eval.in/1057304)
[23:46:55] havenwood: mememeIAMMEE: String#<< is a method too.
[23:47:11] havenwood: mememeIAMMEE: I'm confused what you're trying to do.
[23:47:23] havenwood: mememeIAMMEE: Do you want to change the Hash key or value?
[23:47:27] mememeIAMMEE: What's the # for? I thought it was only used for comments and string parsing.
[23:47:43] mememeIAMMEE: i want to append a value
[23:48:02] havenwood: mememeIAMMEE: If the value is an Array, you can append to it with Array#<<, just like you seem to be thinking.
[23:48:13] havenwood: mememeIAMMEE: The # in Array#<< just means an instance method
[23:48:26] havenwood: [] << 42 #=> [42]
[23:48:28] mememeIAMMEE: so from hash[:key] => [0, 1, 2] to hash[:key] => [0, 1, 2, 3]
[23:48:36] havenwood: mememeIAMMEE: yup, that works
[23:48:45] havenwood: mememeIAMMEE: the Array key will mutate to add the new item
[23:48:50] havenwood: Array value**
[23:48:54] havenwood: now I'm doing it too!
[23:49:14] mememeIAMMEE: Is there somewhere I can post my program so I don't spam irc?
[23:49:22] xall: has joined #ruby
[23:49:22] ruby[bot]: https://gist.github.com - Multiple files, syntax highlighting, even automatically with matching filenames, can be edited
[23:49:40] havenwood: Or https://dpaste.de/ if you don't have a Github acct.
[23:49:47] chouhoulis: has joined #ruby
[23:50:14] havenwood: mememeIAMMEE: You can create a Hash with a default value of an empty Array like: my_hash = Hash.new { |h, k| h[k] = [] }
[23:50:26] mememeIAMMEE: This isn't working https://dpaste.de/eSDx
[23:50:37] havenwood: >> my_hash = Hash.new { |h, k| h[k] = [] }; my_hash[:example] << 42; my_hash
[23:50:38] ruby[bot]: havenwood: # => {:example=>[42]} (https://eval.in/1057305)
[23:51:01] havenwood: mememeIAMMEE: The default value for that Hash is `nil`, and you can't shovel onto `nil`.
[23:51:20] mememeIAMMEE: I thought I was adding a key
[23:51:25] havenwood: >> {}.default
[23:51:26] ruby[bot]: havenwood: # => nil (https://eval.in/1057306)
[23:51:39] havenwood: mememeIAMMEE: When you add a key, the corresponding default value is `nil`.
[23:51:42] havenwood: >> {}.default
[23:51:48] ruby[bot]: havenwood: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
[23:52:41] havenwood: mememeIAMMEE: So this is trying to shovel `42` onto `nil`:
[23:52:42] havenwood: >> {}[:example] << 42
[23:52:43] ruby[bot]: havenwood: # => undefined method `<<' for nil:NilClass (NoMethodError) ...check link for more (https://eval.in/1057307)
[23:52:56] havenwood: mememeIAMMEE: Hence: undefined method `<<' for nil:NilClass
[23:53:16] havenwood: mememeIAMMEE: Compare with:
[23:53:17] havenwood: >> Hash.new { |h, k| h[k] = [] }[:example] << 42
[23:53:18] ruby[bot]: havenwood: # => [42] (https://eval.in/1057308)
[23:53:41] mememeIAMMEE: Ahh so I was simply declaring my hash incorrectly. Thank you
[23:54:47] jottr: has joined #ruby
[23:55:29] chouhoulis: has joined #ruby
[23:56:01] havenwood: mememeIAMMEE: No prob - this is another way to write it:
[23:56:02] havenwood: >> h = {}; h.default_proc = -> h, k { h[k] = [] }; h[:example] << 42
[23:56:03] ruby[bot]: havenwood: # => [42] (https://eval.in/1057309)
[23:57:08] cagomez: has joined #ruby
[23:57:14] mememeIAMMEE: Any simpler, easier to remember, ways to write it? Trying to stuff a bunch of new syntax in my head for an interview in 3 days. Never touched Ruby in my life.
[23:57:43] mememeIAMMEE: Many differences from my usual
[23:58:10] za1b1tsu: has joined #ruby
[23:58:56] havenwood: mememeIAMMEE: Instead of a default proc of an empty Array, you can manually make sure there's an Array for your value before shoveling:
[23:58:57] havenwood: >> h = {}; h[:example] ||= []; h[:example] << 42
[23:58:58] ruby[bot]: havenwood: # => [42] (https://eval.in/1057311)
[23:59:09] cagomez: has joined #ruby