#ruby - 13 March 2018
« Back 1 day Forward 1 day »
[03:22:33] lopezd: Hello everyone. I have a question regarding inheritance and attribute accessors anyone able to offer some guidance?
[03:23:41] lopezd: lets say i have an Animal class with an initialize method that sets @type=mamal and has a private attr_reader :type
[03:24:29] lopezd: when i define a subclass Animal > Dog in the Dogs initialize method i print type and i get mammal as expected
[03:25:06] lopezd: first question why i can set the type to a new value inside the Dog class when only an attr_reader and not an attr_accessor is defined?
[03:26:10] dminuoso: lopezd: attr_accessor/attr_reader are just for external access, and they are only shorthands for: `def foo=(a); @foo = a; end` and `def foo; @foo; end`
[03:26:44] lopezd: I see, exactly then i was wondering of the meaning of having a private external accessor....
[03:28:04] dminuoso: lopezd: attr_accessor is generally a rather bad thing because you no longer can maintain an invariant.
[03:28:21] dminuoso: lopezd: attr_reader is generally fine, but depends on whether you want to leak internals
[03:32:26] dminuoso: lopezd: Just initialize it in your initializer, and demand that descendants call `super`
[03:33:10] lopezd: so accessors should only be used when you need access to a variable after a class is instantiated right?
[03:34:20] ruby[bot]: lopezd: we in #ruby do not like pastebin.com, I reposted your paste to gist for you: https://gist.github.com/1b8bda6da92e85fc57e329ec2c03f046
[03:34:20] ruby[bot]: lopezd: pastebin.com loads slowly for most, has ads which are distracting and has terrible formatting.
[03:37:17] lopezd: man trying so hard to follow all the guidelines i am shooting myself in the face haha
[03:38:36] lopezd: i have been avoiding the use of @@ but have been using private attr_readers, writers module_function private_class_method etc
[03:39:30] lopezd: i am just perplexed at the use of private accessors they seem to be useless. i can just say private @type right?
[03:41:00] dminuoso: lopezd: So you only set them in #initialize if you need to enforce some invariant about their content
[03:42:23] dminuoso: lopezd: Right. And if you want that to propagate through inheritance, then require descendants to call `super/super()` in their #initialize
[03:42:32] lopezd: so in a subclass once i call super in initialize i get access to those @ define in the parent class?
[03:44:33] lopezd: another thing i noticed, the reek example i shared earlier, if the subclass does not define initialize the parent class @variable omg is accessible without @ that is because of the reader right?
[03:45:19] lopezd: maybe that is a "good use" of a private reader accessing variable through a method albeit a bit confusing when seen from subclass
[03:55:04] dminuoso: lopezd: well it just so happens, that attr_reader turns the second into the first.
[03:55:27] dminuoso: lopezd: but just seeing an `invocation` of `foo` of course does not guarantee that.
[03:57:36] lopezd: if i define an ivar in the top of class (outside) initialize it is accessible to all the methods but if I do @foo in a method then it is only accessible in that method right?
[07:08:15] morfin60: i am not sure how implement next thing: i need to perform some job for different "accounts" with execution limit(let's say 35 time per day) for each account
[07:09:45] morfin60: what you'd use for this: Sidekiq? parallel? Let's assume most of time threads will be idling so i don't need N threads all the time
[09:09:11] _sfiguser: hello all, when designing ruby software, are you using UML or it is something you don't usually do ?
[09:10:41] burgestrand: _sfiguser not usually, but occasionally, definitely more often when discussing database layout
[09:57:36] za1b1tsu: dminuoso, regarding tags, I am using ripper-tags, with gutentags(auto generates tags) with deoplete autocomplete. Everything was great, but as usual I wanted more, I wanted tags from the gemfiles, so I got gem-ripper-tags which is basically tpopes' ctags but with ripper-tags, that generates tag files for the gems. To include those tag files, I use vim-bundler, but now deoplete does not use the tags in my main project folder. Did you ever try to setup
[09:59:59] dminuoso: Oh nothing, I was just making a sarcastic joke by suggesting you try out spacemacs.
[10:33:41] _sfiguser: hello all, can somebody suggest me a good starting point for beginners who want to start with RoR ?
[10:35:19] ruby[bot]: _sfiguser: Please join #RubyOnRails for Rails questions. You need to be identified with NickServ, see /msg NickServ HELP
[10:53:59] Bish: conftest.c:3:29: schwerwiegender Fehler: wand/MagickWand.h: Datei oder Verzeichnis nicht gefunden
[10:55:25] Bish: damn now i have to get rid of ze zikret plan to take over ze world with imagemaKICK
[10:59:51] Bish: dminuoso: at home i only install en translations of software, but have de_DE.UTF-8 for locale.. at work i forgot to only activiate the building of english translations
[11:06:19] leitz: German is on my list of languages to learn. Sadly, I have more desired languages than brain cells.
[11:07:09] Bish: leitz: if you ask me, german is only good for poetry, it's not really logical, but you can express alot with one word.
[11:08:33] dminuoso: Bish: Huh? No. It's one of the cleanest compiler implementations Ive seen. I dived in last week and did some minor modifications with ease.
[11:09:23] dminuoso: Bish: Well it has become slower, but you need to have a pretty hefty project to feel the pain though.
[11:09:25] Bish: i read about a survey where people had to say, what they hate most about haskell, that it compiles so slow
[11:09:47] dminuoso: Bish: For a long while the focus has been on writing a clean implementation with a focus on features.
[11:10:00] dminuoso: Bish: But there are regression tests that prevent the compiler from getting slower in place now.
[11:12:10] leitz: In reading Booch's "Object Oriented Design and Analysis", he talks a lot about Smalltalk. After reading it some of the Ruby-ism's seem familiar. In "Mastering Ruby Closures" the author likes Haskell, too.
[11:12:37] dminuoso: Bish: Well lens kind of goes overboard with operators.. but beyond that its kind of okay.
[11:12:37] Bish: leitz: it struck me when i was doing ruby professionelly for 2 years.. when i noticed
[11:13:00] Bish: that ruby is really ONLY ONLY boxes(methods + attributes) sending messages to each other
[11:13:12] dminuoso: Bish: there's only a couple to keep in mind like <>, <$>, <*>, *>, <*, >>=, >>, (.)
[11:14:05] leitz: Bish, I'm slowly catching on. However, my brain translaste "Objects" to "nouns", or "things".
[11:15:18] Bish: leitz: object = a circle, which is closed, methods are doorways to that closed circle (the only way to talk to it)
[11:16:24] dminuoso: Bish: well the notion of "why not make concurrency the default..." is extremely cool
[11:19:12] dminuoso: Bish: Fun fact.. Applicatives too are monoids in (another) the monoidal category of endofunctors..
[11:20:03] dminuoso: Bish: Recently had someone who wanted to know how to chain functions "a -> Maybe b", told him to use >>=, and he responded with "but I dont know what a monad is" - "dont think about it, you're using it already"
[11:27:42] leitz: Bish, thanks. The "boxes" comment is clicking through my brain. I read an beginning Go lang book and the discussion of "interfaces" matches the boxes and may solve a Ruby problem for me.
[12:08:57] Bish: leitz: interfaces do not really exists, but you can imagine them a bit like templates for these boxes, that make sure certain methods exist
[12:13:16] leitz: Bish, but the idea is there. As long as classes A, B, and C are coded to take method a with attribute b, then calling Object Z can assume a reasonable interface.
[12:20:25] Bish: and OOP really makes more pain than gain in the end, that's why i would love pure functional in the end
[12:24:57] burgestrand: Bish not sure if you got an answer to your video question, but I'd recommend creating an actual video with ffmpeg
[12:25:39] dminuoso: Bish: But.. as it so happens, Ill be travelling to PB over the easter holidays.
[12:40:41] Bish: leitz: go play with your boxes! and only stop if you wrote something better than rack!
[12:42:26] leitz: I'm working on fiction and a character generator/tracker so I can remind myself what some looks like or what they do.
[13:20:46] leitz: Is there a way to get uninitialized attr_accessors in something like mything.instance_variables?
[13:26:13] leitz: tbuehlmann, if I have an object with attributes listed under attr_accessor, but not yet set, is there a way to query the object to get the full list of attributes?
[13:27:46] dminuoso: leitz: Considering your current level of expertise, I'm going to say: "Yes but forget about it"
[13:28:25] tbuehlmann: sounds about right. I could only assume what you mean and suggest `YourClass.instance_methods(false)`, but it's probably not the thing you want or the thing that's useful.
[13:50:52] nachooo: Hi. Using Ruby's Resolv::DNS, how can I distinguish between the following situations? [No record in DNS for a given name, DNS server timeout, DNS server not reacheable] In all cases Resolv::DNS::getaddress() seems to raise Resolv::ResolvError.
[13:51:49] nachooo: Bish: the .message seems to be the same in all cases "DNS result has no information for foo.example.com" :/
[13:52:17] Bish: if there aren't more attributes / different classes, there is nothing you can do except for grepping from that messae
[13:52:56] nachooo: I'm afraid that there's nothing to grep for, it's always the same message not matter what's the error situation :/
[13:53:53] nachooo: I've tried with a machine that's not replying to DNS requests (nothing listening), another one listening but never replying and another one that's listening, ready to reply but the traffic filtered out by the network.
[13:54:39] Bish: but i would like the process to not take new jobs / finish existing ones, and then exit
[13:56:12] nachooo: this is particularly painful if the client wants to take an action if a given host is not known to DNS as it could make wrong decisions if the DNS server is not available
[13:56:56] workmad3: nacho__: there's no way to tell those particular 3 cases apart anyway... the worrying thing is the error being the same for no result vs network issue
[13:57:08] nachooo: I need to know basically if either there's no record in the DNS server for a given name or it's just a failure resolving.
[14:42:12] Bish: dminuoso: i was really hoping you will keep on telling me how to make clean shutdown :D
[14:43:22] dminuoso: Bish: The thing is, while emacs is awesome, its not good enough to write code on its own
[14:54:45] tbuehlmann: dminuoso: when using trailblazer cells, do you have the need for model decorators/presenters at all?
[15:00:16] dminuoso: tbuehlmann: No. You can simply do higher-order-cells (as in HOFs) if you want abstraction.
[15:03:57] tbuehlmann: how do you handle things like current_user? when using cells inside actionview templates, I'd pass the current_user object to the cell, current_user coming from a helper though, which is contrary to cell's idea. so, what to do? simply rendering cells from the controller without any actionview involved?
[15:06:08] tbuehlmann: they haven't bitten me yet, but I can see how they could. that's why I'm studying cells
[15:07:47] dminuoso: tbuehlmann: I have a simple pattern - the few helpers I like to use I put into mixins
[15:08:09] dminuoso: tbuehlmann: then for example in one of my layout cells I have: class FooCell < ApplicationCell; include Apax::Devise; end
[15:08:38] dminuoso: tbuehlmann: https://gist.github.com/dminuoso/aa1843aacb97a3f095c9f78c18fb5e69 and that's that helper
[15:09:47] dminuoso: But there's no real reason to do this. It'd be better if I actually pass the user object through.
[15:10:04] dminuoso: (The justification for my style is just that its a reminent from switching to cells)
[15:17:17] dminuoso: tbuehlmann: The rationale is passing arguments just admits dependencies. Code that does not depend on global state is less brittle and _FAR_ easier to test.
[15:18:08] dminuoso: tbuehlmann: The second that current_user is an argument that is passed down, it becomes ridiculously simple to test the cell in isolation, because you can pass it whatever `user` object you desire without having to build an entire rack stack just to make devise happy
[15:24:09] tbuehlmann: on the other side, I'm really tempted to try CurrentAttributes for really simple things like current_user *ducks*
[16:50:22] kspencer: I've got a thor class and a Sinatra::Base subclass in separate files but are in the same gem, I want to be able to pass in the command line options or at least set some settings in the server to be able to pull from at runtime, but I'm not seeing a way to do it without mudding up my code
[16:51:19] kspencer: tldr how can i pass in some variables into a Sinatra::Base subclass server before its initialized and started, and when its in another file
[16:58:38] kspencer: Code here -> https://github.com/IotaSpencer/site_hook/tree/dev the thor subclass is in bin/site_hook, and the sinatra::base subclass is in lib/site_hook.rb
[17:57:16] nme13: how to specify URL like in the gemfile as we do for git gems for example ? my url is a rubygem geminabox server
[20:38:37] remix2000: Hey, have you experienced problems with SSL/https when using the latest version of Puma? I have the same problem as described here: https://git.io/vxUQL
[21:58:52] IshMael_: source in this gist: https://gist.github.com/anonymous/49b9a0a42068cdee0f806fc239d5e9b4
[21:59:54] IshMael_: can someone explain to me, why i have to place a self in front of the instance variable? The method is placed in the singleton class of that object as far as i understand
[22:03:18] havenwood: IshMael_: You could do `@name = "Fred"` to set the instance variable directly. If you try `name = "Fred"` you're just setting a local variable.
[22:03:42] havenwood: IshMael_: `self.name = "Fred` is using the setter method to set the instance variable.
[22:04:29] havenwood: IshMael_: The shorthand for creating that getter and setter method on user is: class User; attr_accessor :name end
[22:04:49] IshMael_: havenwood: so the method definition that is inside of that block doesnt need the self cause it is set already?
[22:05:20] IshMael_: havenwood: it is not for a concrete programming problem. it is just learning and understanding
[22:06:31] IshMael_: havenwood: i was just wondering, why the method definition doesnt need the self in front of and the instance variable needed it ..that confused me a bit
[22:09:40] apeiros: `self.name =` is not the instance variable. it's a method call (which in turn will set the instance variable)
[22:11:26] havenwood: It feels strange to have #filter in Ruby on nightly: [1, 2, 3].filter(&:odd?) #=> [1, 3]
[22:12:03] havenwood: apeiros: I'm actually happy to have filter/map/reduce just so we can all use the same terms.
[22:13:20] apeiros: I'm a select/map/inject person. but as said, I'd much rather settle for a single name.
[23:33:59] zenspider: isn't filter an alias for grep and grep can now take predicate methods? I thought I read something to that effect
[23:40:32] havenwood: there's an issue open for select/filter/reject taking threequals matches as well, which makes sense to me