havenwood changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.7.0, 2.6.5, 2.5.7: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.de/ and select Ruby as the language | Rails questions? Ask in #RubyOnRails | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | Can't talk? Register/identify with Nickserv first!
DTZUZU has joined #ruby
ElFerna has joined #ruby
SeepingN has quit [Quit: The system is going down for reboot NOW!]
ElFerna has quit [Quit: ElFerna]
orbyt_ has joined #ruby
gitter1234 has quit [Quit: Connection closed for inactivity]
GodFather has quit [Ping timeout: 258 seconds]
alfiemax has joined #ruby
sphex has quit [Ping timeout: 255 seconds]
sphex has joined #ruby
hiroaki has quit [Ping timeout: 240 seconds]
TCZ has joined #ruby
wildtrees has quit [Quit: Leaving]
Swyper has quit [Remote host closed the connection]
markoong has quit [Ping timeout: 256 seconds]
yelloB has joined #ruby
yelloB has quit [Remote host closed the connection]
bvdw has quit [Read error: Connection reset by peer]
bvdw has joined #ruby
yelloB has joined #ruby
yelloB has quit [Remote host closed the connection]
ur5us has quit [Remote host closed the connection]
ur5us has joined #ruby
gix has quit [Ping timeout: 258 seconds]
mre- has joined #ruby
mre- has quit [Ping timeout: 240 seconds]
alfiemax has quit [Ping timeout: 255 seconds]
alfiemax_ has joined #ruby
davispuh has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
gitter1234 has joined #ruby
cschneid_ has joined #ruby
cschneid has quit [Ping timeout: 255 seconds]
alfiemax_ has quit [Remote host closed the connection]
leitz has quit [Quit: Leaving]
Swyper has joined #ruby
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
pupsikov has joined #ruby
Swyper has quit []
alfiemax has joined #ruby
alfiemax has quit [Ping timeout: 255 seconds]
ChmEarl has quit [Quit: Leaving]
dviola has joined #ruby
mre- has joined #ruby
mre- has quit [Ping timeout: 240 seconds]
TCZ has quit [Quit: Leaving]
chalkmonster has joined #ruby
impermanence has joined #ruby
dhollinger has quit [Ping timeout: 255 seconds]
braincrash has quit [Quit: bye bye]
dhollinger has joined #ruby
braincrash has joined #ruby
cschneid has joined #ruby
cschneid_ has quit [Ping timeout: 255 seconds]
chalkmonster has quit [Quit: WeeChat 2.7.1]
ur5us has quit [Ping timeout: 240 seconds]
gitter1234 has quit [Quit: Connection closed for inactivity]
jmcgnh has quit [Read error: Connection reset by peer]
jmcgnh has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ttoocs has joined #ruby
jetchisel has quit [Quit: Unfortunately time is always against us -- [Morpheus]]
jetchisel has joined #ruby
mre- has joined #ruby
cd has quit [Quit: cd]
cthulchu has quit [Ping timeout: 255 seconds]
mre- has quit [Ping timeout: 265 seconds]
sauvin has joined #ruby
_ikke_ has left #ruby ["WeeChat 2.7"]
pupsikov has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pandakekok9 has joined #ruby
xco has quit [Ping timeout: 255 seconds]
cschneid_ has joined #ruby
cschneid has quit [Ping timeout: 255 seconds]
markopasha has joined #ruby
markopasha has quit [Remote host closed the connection]
lxsameer has quit [Ping timeout: 255 seconds]
markopasha has joined #ruby
sdu has joined #ruby
<roadie> is there a ruby mailinglist that has archives in mbox or plaintext format for download?
Tempesta has quit [Read error: Connection reset by peer]
Tempesta has joined #ruby
jetchisel has quit [Ping timeout: 255 seconds]
lxsameer has joined #ruby
bvdw has quit [Read error: Connection reset by peer]
bvdw has joined #ruby
chalkmonster has joined #ruby
jetchisel has joined #ruby
alexherbo2 has joined #ruby
fercell has joined #ruby
mre- has joined #ruby
vondruch has joined #ruby
mre- has quit [Ping timeout: 255 seconds]
postmodern_ has joined #ruby
postmodern has quit [Ping timeout: 258 seconds]
hiroaki has joined #ruby
chalkmonster has quit [Quit: WeeChat 2.7.1]
chalkmonster has joined #ruby
pandakekok9 has quit [Quit: leaving]
cliluw has quit [Ping timeout: 258 seconds]
cschneid has joined #ruby
cschneid_ has quit [Ping timeout: 265 seconds]
vqrs has quit [Ping timeout: 246 seconds]
vqrs has joined #ruby
Ai9zO5AP has quit [Quit: WeeChat 2.7.1]
code_zombie_ has joined #ruby
code_zombie has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #ruby
dionysus69 has joined #ruby
xco has joined #ruby
dinfuehr has quit [Ping timeout: 260 seconds]
dinfuehr has joined #ruby
cschneid has quit [Quit: ZNC 1.7.5 - https://znc.in]
schne1der has joined #ruby
TomyWork has joined #ruby
BartPB has joined #ruby
cschneid has joined #ruby
arahael has quit [Ping timeout: 256 seconds]
al2o3-cr has quit [Ping timeout: 256 seconds]
arahael has joined #ruby
al2o3-cr has joined #ruby
mre- has joined #ruby
al2o3-cr has quit [Quit: WeeChat 2.7.1]
mre- has quit [Ping timeout: 240 seconds]
conta has joined #ruby
ellcs has joined #ruby
conta has quit [Client Quit]
<TomyWork> I'm trying to parse confluence markup. that's basically xml fragments with embedded html, including html entities like &auml;
<TomyWork> by wrapping the fragments in <ac:confluence xmlns:ac=\"http://www.atlassian.com/schema/confluence/4/ac/\" xmlns:ri=\"http://www.atlassian.com/schema/confluence/4/ri/\">...</ac:confluence> I was able to parse the thing, even with namespaces intact
<TomyWork> but nokogiri seems to discard all the HTML entities
<TomyWork> and in HTML mode, it doesn't like the namespaces
<TomyWork> so what do I do? :)
<roadie> I want to install git-lfs via homebrew. this requires homebrew ruby which will install to /usr/local I think. I have ruby via rvm - is this going to cause problems having the 'additional' ruby from homebrew?
sergioro has quit [Quit: leaving]
<jhass> roadie: it shouldn't
<roadie> jhass: thank you - installing
iNs has quit [Remote host closed the connection]
iNs has joined #ruby
<TomyWork> i put this in front of it, which seems to at least make it parse the entities: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
markoong has joined #ruby
kevinburke has quit [Quit: Connection closed for inactivity]
<TomyWork> so does anyone know how to tell nokogiri to replace all the HTML entities in an XML document? :)
markong has joined #ruby
markoong has quit [Ping timeout: 256 seconds]
davor_ has joined #ruby
dionysus69 has quit [Quit: dionysus69]
davor has quit [Ping timeout: 256 seconds]
davor_ is now known as davor
dionysus69 has joined #ruby
<jhass> maybe easiest is to just postprocess with something like https://rubygems.org/gems/htmlentities
leitz has joined #ruby
<TomyWork> oh that is nice, thanks jhass
dionysus69 has quit [Client Quit]
dionysus69 has joined #ruby
<TomyWork> jhass, problem: it also decodes necessary entities :)
<TomyWork> like an encoded <!--
<jhass> that's why said "postprecess" instead of "preprocess" ;)
<jhass> eh, *process
<TomyWork> for that, i'd have to get nokogiri to give me the text with the entities in the first place :)
<TomyWork> but any xpath expression will discard entities
cschneid_ has joined #ruby
cschneid has quit [Ping timeout: 268 seconds]
<jhass> I think I didn't fully grok yet what your XML looks like
<jhass> got a real world example and what you want to get out of it?
Abhijit has joined #ruby
<Abhijit> Hi. can you please suggest some good open source language detection libraries in ruby?
<jhass> programming or natural languages?
TCZ has joined #ruby
<jhass> for the former https://github.com/github/linguist comes to mind
mre- has joined #ruby
<jhass> natural language detection is quite a beast, no idea about the status quo there
<jhass> been some years since I tried to find something for it
<Abhijit> jhass, Natural languages.
<Abhijit> i found two very good, but one in Java and one in Python. was looking for something native ruby.
TCZ has quit [Quit: Leaving]
ldepandis has joined #ruby
<TomyWork> jhass, basically <ac:foo><p>f&uuml;r</p></ac:foo>
mre- has quit [Ping timeout: 256 seconds]
<jhass> Abhijit: I guess your best bet is to go through https://rubygems.org/search?utf8=%E2%9C%93&query=language+detect
<TomyWork> but sometimes the paragraphs have ac: elements embedded as well
<Abhijit> jhass, ok. Thanks. will look there.
<jhass> Abhijit: using the Java one with JRuby might also be an avenue
<TomyWork> and sometimes it's not even paragraphs
<Abhijit> jhass, will it be easy taks to setup ruby on rails using jruby (to use that java library)
<jhass> I never tried myself, but I suspect it not to be too hard. Just note that it'll have a slightly higher base memory foot print and startup time
<jhass> due to running a JVM
<Abhijit> right.
<jhass> other avenues in something like a webapp could also be to make it a background task and run the worker under JRuby or something else
<Abhijit> ok.
markoong has joined #ruby
code_zombie_ has quit [Quit: Leaving]
markong has quit [Ping timeout: 256 seconds]
ElFerna has joined #ruby
<jhass> TomyWork: mmh, I see. I guess technically that's not valid XML, as XML doesn't define any named entities beyond some very basic ones: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
<TomyWork> well i gave it an xhtml doctype, so it's valid :)
<jhass> maybe a preprocessing step that parses out any entities, decodes them, for example using the gem I linked earlier, and then reencodes them to the cannonical &#xx; form can work
<TomyWork> at least valid as far nokogiri cares
<jhass> even if you Nokogiri::XML(foo) {|o| o.strict } ?
alexherbo26 has joined #ruby
<TomyWork> that's in my gist
alexherbo2 has quit [Ping timeout: 255 seconds]
alexherbo26 is now known as alexherbo2
<jhass> ah sorry, overlooked that one somehow
<jhass> yeah, seems legit
burningserenity has joined #ruby
<TomyWork> .accept is next to useless btw :)
<TomyWork> child.accept(self) is equivalent to self.visit(child)
<jhass> well, visitor pattern, eh?
<TomyWork> but it looks nice and visitorpatterny
<TomyWork> it looks like i know wtf i'm doing
stryek has joined #ruby
drincruz has joined #ruby
postmodern_ has quit [Quit: Leaving]
BartPB has quit [Ping timeout: 256 seconds]
<TomyWork> I'm trying to find an xpath expression that will match both <br/> and text nodes
<TomyWork> so i can build text from them
<TomyWork> seems to be hard, because .//* already discards all text nodes
Abhijit has quit [Quit: Leaving]
jcalla has joined #ruby
<jhass> what am I missing? '//text()|//br'
<TomyWork> yep that works, thanks
<TomyWork> i guess https://de.wikipedia.org/wiki/XPath is not the best xpath doc
<jhass> take care libxml2/nokogiri is xpath 1.1 still, no xpath 2.0 sugar
cyberarm has joined #ruby
<TomyWork> yeah but this page didn't even list the |
yokel has quit [Ping timeout: 258 seconds]
kaleido has quit [Quit: ZNC 1.7.4+deb7 - https://znc.in]
kaleido has joined #ruby
yokel has joined #ruby
LnxBil has joined #ruby
<LnxBil> Hi everybody! Is there a predefined regexp I can use to validate a hostname? For an IP there is Resolv::IPv4::Regex, what about a hostname?
kinduff has quit [Quit: gg]
<jhass> isn't it just [a-z]([a-z0-9-]\.?)* ?
<leitz> LnxBil, hostnames can be a variety of things. If you mean "a string that would be a valid hostname", that's one thing. If you mean "the name of a host that's in the domain name system", that's another.
<LnxBil> leitz: Only the RFC definition, I don't want to resolve it.
<LnxBil> leitz: I found a bunch of different implementation, but I really like to build upon work that is already present in ruby somewhere and do not want to define it myself in my code.
<LnxBil> leitz: One way to do it is via URI.parse("http://#{hostname}/")...
<jhass> honestly, most of the time you don't need to validate it, just try to use it and let it fail there if invalid
kinduff has joined #ruby
<LnxBil> jhass: Yes, that was my intention until now, but the input is used "further down the pipeline" and it crashed there.
<jhass> so it's user input? probably worth to try to punycode it and then check with something like above
<jhass> but valid doesn't mean existing, so it doesn't seem like you can prevent all possible failures here
alexherbo24 has joined #ruby
alexherbo2 has quit [Ping timeout: 258 seconds]
alexherbo24 is now known as alexherbo2
<LnxBil> Yes, existing is another problem, but the input is not resolveable on the system it is inputted. Simple validation would be sufficient.
<LnxBil> I just find it odd, that there is no "official" Regexpr (in whatever RFC-format) already presend in Ruby like Resolv::IPv4::Regex.
<LnxBil> or at least I could not find it. If there is none, that is also an answer I can live with
<jhass> honestly that's more of an implementation detail
<jhass> I'd think about how to turn the "crash" into an error case that can be propagated back up to the user
lucasb has joined #ruby
<leitz> LnxBil, I see what you mean. Making an RFC compliant parser could be a project.
<leitz> To have a '-r' option to actually test by DNS resolution.
<LnxBil> jhass: It is deployed in a docker-based cloud on the customer side and the invalid entry turns up in a docker-compose.yml ... so no back channel.
<LnxBil> But thanks for all suggestions, I'm going to use the URI.parse stuff.
bvdw has quit [Read error: Connection reset by peer]
bvdw has joined #ruby
markopasha has quit [Ping timeout: 258 seconds]
TCZ has joined #ruby
markopasha has joined #ruby
cschneid has joined #ruby
TzilTzal has joined #ruby
cschneid_ has quit [Ping timeout: 268 seconds]
LnxBil has quit [Quit: leaving]
<TzilTzal> Hi
<TzilTzal> If I need to write a server/daemon that just accepts client requests without any views (html, etc..) - should I use RoR or Sinatra? or is there a simpler/better way of doing this?
ElFerna has quit [Read error: Connection reset by peer]
ElFerna has joined #ruby
mre- has joined #ruby
<jhass> so it has to be HTTP requests?
<jhass> how many different kinds of requests/endpoints?
<TzilTzal> Doesn't have to be HTTP.. but it's quite common these days, I'd say...
<TzilTzal> hmmm... not too many. Can't say exactly, but fairly small number.
<jhass> if it's one or two I'd consider just plain rack, otherwise sinatra seems fine
<TzilTzal> Cool. Thanks!
<TzilTzal> Oh, but is it possible to not have views in Sinatra or RoR?
<jhass> of course
<jhass> sinatra just returns whatever the return value of the route block is
<TzilTzal> What about things like authentication and client management? Easy to do with Rack?
<jhass> rails just returns whatever the return value of the action is, essentially
<jhass> depends on what kind of authentication
<TzilTzal> what do you mean?
<jhass> just basic auth? cookie auth? access token?, ...
<TzilTzal> all of the above? )
<jhass> seems like you just don't know :P How would a nice cookie based auth flow look like without a sign in view?
<jhass> anyways, all ruby HTTP server frameworks use rack under the hood
<jhass> so there's some rack based authentication frameworks, like for example warden
<jhass> whether that's easy is kinda subjective, whether it fits you need I don't know, everything seems too vague to guess
<adam12> TzilTzal: You probably just want to use Rails. There's also rails-api which is Sinatra like in terms of liteness.
<adam12> TzilTzal: Sinatra is great for this (as is Roda, hanami-api) but you need to assemble a lot of pieces yourself. If you're not familiar with how to do that it can be a huge time sink.
TCZ has quit [Quit: Leaving]
fluxAeon has quit [Ping timeout: 256 seconds]
burningserenity has quit [Ping timeout: 260 seconds]
pupsikov has joined #ruby
fluxAeon has joined #ruby
Tungki has joined #ruby
lxsameer has quit [Ping timeout: 260 seconds]
ElFerna has quit [Ping timeout: 265 seconds]
TzilTzal has quit [Quit: Leaving.]
burningserenity has joined #ruby
TCZ has joined #ruby
ElFerna has joined #ruby
ElFerna has quit [Client Quit]
ldepandis has quit [Ping timeout: 260 seconds]
Tungki has quit [Ping timeout: 252 seconds]
fluxAeon has quit [Ping timeout: 265 seconds]
chalkmonster has quit [Quit: WeeChat 2.7.1]
fluxAeon has joined #ruby
mre- has quit [Ping timeout: 258 seconds]
ellcs has quit [Ping timeout: 256 seconds]
lightstalker has quit [Remote host closed the connection]
lxsameer has joined #ruby
markopasha has quit [Remote host closed the connection]
ChmEarl has joined #ruby
thecoffemaker has quit [Ping timeout: 256 seconds]
mre- has joined #ruby
paraxial2 has joined #ruby
mre- has quit [Ping timeout: 260 seconds]
paraxial has quit [Ping timeout: 255 seconds]
paraxial2 is now known as paraxial
d3bug has joined #ruby
yelloB has joined #ruby
yelloB has quit [Remote host closed the connection]
conta1 has joined #ruby
cschneid has quit [Ping timeout: 256 seconds]
cschneid has joined #ruby
SanguineAnomaly has joined #ruby
GodFather has joined #ruby
pupsikov has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
burningserenity has quit [Ping timeout: 258 seconds]
ttoocs has quit [Ping timeout: 256 seconds]
fluxAeon has quit [Ping timeout: 260 seconds]
fluxAeon has joined #ruby
orbyt_ has joined #ruby
sdu has quit [Quit: leaving]
burningserenity has joined #ruby
kristian_on_linu has joined #ruby
fluxAeon has quit [Ping timeout: 265 seconds]
TCZ has quit [Quit: Leaving]
TCZ has joined #ruby
markopasha has joined #ruby
markopasha has quit [Remote host closed the connection]
markopasha has joined #ruby
cthulchu has joined #ruby
fercell has quit [Quit: WeeChat 2.7]
ellcs has joined #ruby
schne1der has quit [Ping timeout: 265 seconds]
Ai9zO5AP has joined #ruby
TCZ has quit [Quit: Leaving]
ellcs has quit [Ping timeout: 240 seconds]
cd has joined #ruby
mre- has joined #ruby
kinduff has quit [Read error: Connection reset by peer]
kinduff has joined #ruby
mre- has quit [Ping timeout: 256 seconds]
troulouliou_div2 has joined #ruby
dviola has quit [Ping timeout: 260 seconds]
noboruma has joined #ruby
pupsikov has joined #ruby
SCHAPiE has quit [Quit: ZNC - https://znc.in]
ElFerna has joined #ruby
conta1 has quit [Quit: conta1]
SCHAPiE has joined #ruby
ldepandis has joined #ruby
cschneid has quit [Ping timeout: 240 seconds]
cschneid has joined #ruby
mre- has joined #ruby
NODE has quit [Quit: changing servers]
NODE has joined #ruby
plujon has joined #ruby
mre- has quit [Ping timeout: 255 seconds]
<plujon> Greetings. I am seeking a succinct description of API changes in various ruby versions. Is there a page dedicated to this? I've found https://www.ruby-lang.org/en/news/ , but it takes a fair amount of scrolling and clicking to navigate.
<plujon> As an example, I'm about to document that MyClass.alias_method is private in some versions of ruby (such as 2.3), but that it isn't private in newer versions (such as 2.5.1).
<plujon> I'm curious when it became private, and if there's a document where I can discover such things. I develop using Ruby 2.5 and deploy to Ruby 2.3 machines, and that's bitten me a couple times.
<adam12> plujon: Maybe the unofficial ruby references site? https://rubyreferences.github.io/rubychanges/
xco has quit [Remote host closed the connection]
NODE has quit [Quit: changing servers]
<plujon> adam12: Looks like what I'm after; thanks!
NODE has joined #ruby
<plujon> Bam: https://rubyreferences.github.io/rubychanges/2.5.html # alias_method became public
donofrio_ has quit [Quit: Leaving]
donofrio has joined #ruby
<plujon> Wow, this site is *exactly* what I wanted.
<adam12> plujon: Yeah. zverok did a great job.
<adam12> plujon: Probably deserving of a beer if you ever meet them.
<adam12> Between that and rubyapi.org, docs are getting much better.
<adam12> (and the stabilities that lsegal have been doing to rubydoc.info)
cliluw has joined #ruby
NODE has quit [Client Quit]
NODE has joined #ruby
sauvin has quit [Read error: Connection reset by peer]
<plujon> There's a patreon link. As of a few minutes ago, he had 0.
<leitz> Well, I converted my shell code style crewgen to something that might be mistaken for a Builder design pattern. Assuming you squint a bit, and are half drunk.
<leitz> Still working on the whole design pattern concept. I get the concept, but implementation is a different beast.
d3bug has quit [Quit: Connection closed for inactivity]
<havenwood> leitz: Is it better before or after the refactor?
<leitz> havenwood, well....
gix has joined #ruby
<leitz> havenwood, it passes the tests, keeps one of the object from knowing stuff it shouldn't, creates one less class, where it shouldn't, and is mildly extendable.
<havenwood> leitz: Hash#fetch is really handy, and tends to be underused. For example, on this line it'd be great: https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/crew_builder.rb#L35
TomyWork has quit [Remote host closed the connection]
<havenwood> leitz: @ship.fetch(:weapons, 0)
<havenwood> leitz: If there's a `:weapons` key, return the value, otherwise `0`.
<leitz> havenwood, there's still a lot to do; many of the recommendations you made are on the agenda. However, I fried both brain cells this morning, just getting the basic functionality.
<havenwood> leitz: Drop the `? true : false` here, since it's already `true` or `false` and this is just redundant code: https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/crew_builder.rb#L43
<havenwood> leitz: Always be suspicious if you see an `if foo true else false`.
<leitz> havenwood, let me try that. There were three iterations of that method, they failed when there was no weapons key in the hash.
<havenwood> leitz: If you're using #[], consider if it should be #fetch instead.
<havenwood> leitz: If you expect the key to be there, or want a fallback if it isn't, use #fetch.
tf2ftw has joined #ruby
<tf2ftw> hello
markopasha has quit [Remote host closed the connection]
gix has quit [Disconnected by services]
<havenwood> tf2ftw: hi
<havenwood> leitz: @ship.fetch(:drive_size).fdiv(35).ceil.clamp(1..)
<leitz> havenwood, fetch works once I remove the default assignment of nil.
bsdbandit-01 has joined #ruby
<havenwood> leitz: What should a default be? The reason for #fetch here is that it'd blow up with a `nil`, but with a worse error.
* leitz goes to ponder fdiv, ceil, and clamp
<havenwood> leitz: #fdiv is division on an Integer when you want a Float result, so you don't have to 35.0.
<havenwood> leitz: You were already using #ceil.
markopasha has joined #ruby
<havenwood> leitz: #clamp is saying ensure it's between these, being 1 as a minimum and no maximum.
<havenwood> leitz: A nice readability refactor to this code would be switching to 1.9+ style Hash symbol keys. So `role: 'Medic'` instead of `:role => 'Medic'`.
<havenwood> (RuboCop should make short work of that with: `rubocop -a`.
<havenwood> )
<leitz> havenwood, I never really 'like' something until I can explain it. Just because I type it, doesn't mean I like it. :)
<leitz> havenwood, and that's why I dislike rubocop's auto-change everything. Worse than gofmt...
<havenwood> leitz: But it'd be standard code that others can read and you'll be learning a style that is lovely and readable.
<leitz> havenwood, which is not to say the idea of style guides is bad, but I prefer to know why I'm doing something.
ElFerna has quit [Quit: ElFerna]
<havenwood> leitz: If you wonder why on any of the RuboCop rules, happy to discuss at length. They're worth following though until you know why not.
<havenwood> leitz: The reason to extract the Arrays is that these methods currently create a new Array every time they're called.
<havenwood> leitz: This puts pressure on the garbage collector (GC), which has to remove them from memory after they're dereferenced after each method call.
<havenwood> leitz: So do like: SIZES = ["very small", "small", "small", "medium", "large"].freeze
<havenwood> leitz: Then in the method: SIZES.sample
<havenwood> leitz: Then you only have one Array ever, instead of a new Array every time.
<havenwood> leitz: Does that make sense?
<leitz> havenwood, yes, it makes sense. One (of many) thing I'm working to understand is "class things" outside of methods and variables. Like, when to use a class variable, or a constant.
<leitz> havenwood, this is one of the code bits I want to use in the 90DW project. So I need to know it well enough to explain well. :)
ElFerna has joined #ruby
<havenwood> leitz: #equal? check if it's the same object ID.
<havenwood> leitz: Extract constant is a good refactor.
<havenwood> leitz: It'd be good to add the frozen string literal magic comment to each file.
* leitz notices fetch works much better if you remember the @ before the variable name...
fanta1 has joined #ruby
<havenwood> leitz: NOBILITY.dig(@upp[:soc], @gender)
<havenwood> leitz: You might want to refactor this with #reduce: https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/character.rb#L28-L35
<leitz> havenwood, in churn.rb, baz.equal? is because it's doing the === comparison, and it's the same object? Where foo.equal?(foo) actually calls foo twice, and created different objects?
<havenwood> leitz: No, it's not doing #=== comparison. They'd all be threequals equal.
<havenwood> leitz: Yes, it's checking if they're the same object. You could alternatively look at #object_id twice.
<havenwood> leitz: #==, #===, #eql?, and #equal? are all different things.
<leitz> havenwood, ah, gotcha. I knew there were some differences, but forgot they were all different.
<havenwood> leitz: You typically use #== and #equal? directly, and define #eql? and #=== on classes to enable functionality for Hashes, case statement, etc.
<havenwood> leitz: #== is by far the most commonly used.
<havenwood> leitz: #equal? if for checking if they're the same #object_id.
<havenwood> leitz: "Unlike #==, the equal? method should never be overridden by subclasses as it is used to determine object identity (that is, a.equal?(b) if and only if a is the same object as b)"
<havenwood> leitz: "The eql? method returns true if obj and other refer to the same hash key. This is used by Hash to test members for equality."
<havenwood> leitz: "Case Equality – For class Object, [#=== is] effectively the same as calling #==, but typically overridden by descendants to provide meaningful semantics in case statements."
<havenwood> leitz: So don't use #eql? and #=== directly. Only define them for their purpose. Generally use #==, unless you really want to know, "Is this the exact same object?"
code_zombie has joined #ruby
<havenwood> leitz: It's not possible there's already a @gender here, so just `=` not `||=`: https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/name.rb#L11
<havenwood> leitz: Let us know if you want more code review! I'd recommend studying Rubocop recommendations, and either adopt them or change the rules sparingly.
FastJack has quit [Ping timeout: 258 seconds]
<leitz> havenwood, what takes you 5 minutes to explain takes me 3-4 hours to digest. I can only comprehend so much havenwood per coding session. :)
<havenwood> leitz: Just let me know if you want more suggestions! :)
<leitz> havenwood, looking at the reduce docs now.
<havenwood> leitz: That's the most complicated of my suggestions today.
<havenwood> leitz: baweaver has a series on reduce with lemurs :) https://github.com/baweaver/reducing_enumerable
fluxAeon has joined #ruby
ElFerna has quit [Ping timeout: 260 seconds]
ElFerna has joined #ruby
oz has quit [Quit: EOF]
howdoi has joined #ruby
<leitz> havenwood, yeah. I just read the reduce doc, and baweaver's page. I think it'll need some time to sink in. :)
postmodern has joined #ruby
FastJack has joined #ruby
bsdbandit-01 has quit [Ping timeout: 272 seconds]
rippa has joined #ruby
<havenwood> &>> ['le', 'it', 'z'].reduce('') { |string_accumulator, letters| "#{string_accumulator}#{letters}" }
<rubydoc> # => "leitz" (https://carc.in/#/r/8pv5)
<havenwood> leitz: That's ^ like a #join but with #reduce.
FastJack has quit [Ping timeout: 258 seconds]
burningserenity has quit [Ping timeout: 240 seconds]
<havenwood> leitz: The argument to #reduce (an empty string in this case) is the first block argument and is replaced by the result of the block on each iteration.
<leitz> havenwood, sort of like ijnect?
<leitz> inject
<havenwood> leitz: #reduce is an alias to #inject.
<havenwood> leitz: (it's called #reduce in most languages)
<leitz> havenwood, ahhhhh
<havenwood> leitz: We say map/reduce these days not collect/inject, which are Smalltalkisms, I believe.
DTZUZU has quit [Ping timeout: 265 seconds]
oz has joined #ruby
<leitz> havenwood, my Smalltalk books aren't here yet. I was hoping for some good weekend reading. :(
<havenwood> leitz: Some say that Ruby is the Smalltalk dialect that thrived. ;)
bsdband74 has joined #ruby
DTZUZU has joined #ruby
<leitz> havenwood, I think of Ruby as "readable Perl". :)
markopasha has quit [Remote host closed the connection]
alexherbo2 has quit [Ping timeout: 268 seconds]
<leitz> havenwood, I've seen a few references to Smalltalk learning being useful for a growing Rubyist. Hence the book order.
markopasha has joined #ruby
markopasha has quit [Remote host closed the connection]
<havenwood> I don't know enough Smalltalk to say. I do think Ruby is the most useful language for a growing Rubyist to learn though.
<havenwood> leitz: Clojure, Elixir, and Rust are a few modern languages I'd recommend a Rubyist look at.
<havenwood> leitz: And the JRuby and TruffleRuby are Rubies to look at.
<leitz> havenwood, my personal challenge is writing Ruby code that doesn't look like my shell code. Specifically, to actually use and understand objects. When doing job interviews, I want to show that I've grown from my sysadmin life to a programmer's way of thinking.
<leitz> havenwood, assuming you programmers think. :) I spent decades fixing things that "worked on my dev computer".
<leitz> As for other languages, I'm torn between C and Go. The former lets me tie into Ruby more directly, the latter has a lot buzz and a growing job list. I'm old, and getting ahead of the implementation curve means I can stick with it until I croak off.
markopasha has joined #ruby
<havenwood> leitz: I'd suggest the simplest thing that can possibly work, then refactor when the refactor improves the code's readability.
<leitz> What's the convention for placing an "alias" stanza? After initialize, and before the defs? At the end?
d3bug has joined #ruby
<havenwood> leitz: Alongside the methods. Just instead of `def ...` do `alias ...`.
<havenwood> leitz: Like def, alias is a keyword.
gitter1234 has joined #ruby
mre- has joined #ruby
* leitz is seriously appreciating those tests, right about now.
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood> leitz: I start by thinking, "How many instances of state do I have?" If none, a module is perfect. If one, consider a singleton class. If many, a class is usually best.
<havenwood> leitz: This code shows an example of each of those: https://gist.github.com/havenwood/a81401724cbcbf1f78e79f42ed4b0e33
<leitz> havenwood, understood on "simplest, then refactor". That was this morning's work. https://github.com/makhidkarun/ftl_tools/blob/master/bin/crewgen
cschneid has quit [Ping timeout: 256 seconds]
cschneid_ has joined #ruby
mre- has quit [Ping timeout: 265 seconds]
<havenwood> leitz: It can sometimes be nice to abstract your option parsing into your gem namespace, then use that clean interface from the executable. For example: https://github.com/pry/pry/blob/master/bin/pry
<havenwood> leitz: Pry has a much more complicated option parser, but the point is the same.
<havenwood> leitz: Keep moving behavior inside your gem namespace.
<leitz> havenwood, yup. I haven't gotten to the option parsing recommendations you made the other day, that's on my agenda.
<havenwood> Nice. Making gradual, constant improvements and then keeping those learnings as you move from project to project will hone your code instincts.
<havenwood> Also, you can poach your old work for patterns, once you establish good ones.
<havenwood> leitz: It's nice to use `value.instance_of?(Array)` I think here: https://github.com/makhidkarun/ftl_tools/blob/master/bin/crewgen#L55
<leitz> havenwood, there was sort of an "a-ha" moment when I realized a Ship should not know about crew requirements, and Crew shouldn't care about what roles were filled. It made the classes much cleaner.
<havenwood> leitz: :D
<leitz> havenwood, while I change that line, that's actually one of my wins for the day. I eliminated a method, and sequencing, there. It was pretty nice, from my Apprentice perspective.
NODE has quit [Quit: changing servers]
CalimeroTeknik has quit [Quit: バイバイ]
NODE has joined #ruby
sagax has quit [Ping timeout: 240 seconds]
<leitz> Before I remembered to just test on the existance of data[:team], the builder needed to call "add_team" itself. https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/crew.rb#L15-L22
NODE has quit [Quit: changing servers]
NODE has joined #ruby
dionysus69 has quit [Remote host closed the connection]
NODE has quit [Client Quit]
NODE has joined #ruby
orbyt_ has joined #ruby
dionysus69 has joined #ruby
ElFerna has quit [Ping timeout: 258 seconds]
NODE has quit [Client Quit]
NODE has joined #ruby
NODE has quit [Remote host closed the connection]
ElFerna has joined #ruby
markopasha has quit [Remote host closed the connection]
kinduff has quit [Quit: gg]
fanta1 has quit [Quit: fanta1]
drincruz has quit [Read error: Connection reset by peer]
<leitz> havenwood, on reduce. Given: skills = { 'GunCbt' => 1, 'Kissing' => 0, 'Adventure' => 3}
drincruz has joined #ruby
<leitz> havenwood, how to eliminate the leading comma? skills.reduce('') { |string_accumulator, letters| "#{string_accumulator},#{letters[0]}-#{letters[1]}" }
NODE has joined #ruby
kinduff has joined #ruby
<apotheon> leitz: It turns out this has been a very busy week for me. Sorry about not getting back to you about stuff.
<havenwood> leitz: skills.reduce('') { |acc, (skill, value)| "#{acc}#{',' if acc.empty?}#{skill}-#{value}" }
<havenwood> leitz: I mean: ',' unless acc.empty?
<leitz> apotheon, no worries! I appreciate what you've done so far. Take your time.
<havenwood> leitz: Alternatively, at the end: remove_prefix(',')
<havenwood> leitz: { |acc, (skill, value)| "#{acc}#{',' unless acc.empty?}#{skill}-#{value}" }
<havenwood> leitz: { |acc, (skill, value)| "#{acc},#{skill}-#{value}" }.remove_prefix(',')
<havenwood> leitz: Those who ^ are two ways.
tf2ftw has quit [Remote host closed the connection]
markopasha has joined #ruby
markopasha has quit [Read error: Connection reset by peer]
<leitz> While busier, visually, I prefer the first. It's a good teaching point; Ruby's ability to computer inside a nested #{} is something that might pleseantly surprise folks.
sagax has joined #ruby
roadie has quit [Read error: Connection reset by peer]
bsdband74 has quit [Quit: -a- Connection Timed Out]
roadie has joined #ruby
roadie has quit [Remote host closed the connection]
lucasb has quit [Quit: Connection closed for inactivity]
gendarme has joined #ruby
<kaleido> anyone offer ways to make this simple script "better"? https://dpaste.org/KSqJ
<kaleido> and please no laughing :D
<adam12> kaleido: Replace while loop with an upto or something that uses Enumerable.
<adam12> 1.upto(num_rolls)
bsdbandit-01 has joined #ruby
<kaleido> adam12: (great name btw) example?
<kaleido> ahh beat me to it :)
<adam12> kaleido: instead of pushing to results, you could just chain upto and map.
<adam12> results = 1.upto(num_rolls).map { rand(1..s) }
<adam12> kaleido: In theory, total is just results.sum?
<kaleido> yes
<adam12> kaleido: So if that's the case, you could just do that at the end. Array#sum is newish so depends on your Ruby version.
<adam12> kaleido: I suggest adding a line the next time you paste code that shows me how to run it. ie. roll(1, 3). I have no idea what numbers to provide.
<leitz> kaleido, for the record, adam12 is one of the folks to listen to. :)
<adam12> kaleido: You assign dice_sides and num_rolls from s, r. I'd probably just make those the method names in the method head.
<adam12> def roll(num_rolls, dice_sides)
<kaleido> ahh good call
<kaleido> and thanks
<adam12> Bonus points, accept them as keyword args so the order don't matter. def roll(num_rolls:, dice_sides:)
<kaleido> trying to learn to do "something" then learn to do it "right"
<leitz> kaleido, the best way to learn.
<adam12> kaleido: Nothing wrong with what you did. Some of these suggestions require deeper Ruby knowledge.
<adam12> (ie. chaining enumerbale)
<adam12> Enumerable O_O
<leitz> That too.
<adam12> (not Christianbale or Batman)
<leitz> kaleido, a simple change, drop line 8 and make line 9 results << rand(1..sides)
<leitz> kaleido, then results.sum
<leitz> I learned about fdiv today, so you could get the average
gendarme has quit [Remote host closed the connection]
<leitz> results.sum.fdiv(results.count)
<adam12> leitz: Hilariously, I dont' recall ever using fdiv. Ever. So that was new to me too.
<adam12> leitz: But havenwood knows all the good new tricks.
<kaleido> so i'm down to this: https://dpaste.org/2NBT
<adam12> kaleido: Looks good to me :)
<leitz> kaleido, have you used printf? It would work if you wanted it all on one line.
<kaleido> i havent but im game to trying anything, ill lookup printf
TorpedoSkyline has joined #ruby
<leitz> Let me test my idea, I'm still working on my Ruby. :)
<leitz> Instead of the two puts lines, try: printf "Total: %d Each die: %s " % [results.sum, results.sort.to_s ]
<_phaul> maybe 1.upto(num_rolls) could be replaced num_rolls.times kaleido
<leitz> Well, add "\n" after the "%s". :) printf doesn't add newlines automatically.
ElFerna has quit [Ping timeout: 260 seconds]
<leitz> And all, I must step away from the screen for a while. Both brain cells are exhausted. Thank you!
ElFerna has joined #ruby
roadie has joined #ruby
<leitz> Okay, one more thing. kaleido: printf "Total: %d Rolls: %s Average: %.2f \n" % [results.sum, results.sort.to_s, results.sum / results.count ]
<apotheon> _phaul: Yeah, that's kind of a standard #times use case right there.
<kaleido> _phaul: and still .map after? num_rolls.times.map { blahblah }
<kaleido> ?
dviola has joined #ruby
<_phaul> yeah, you need map to make it work
<leftylink> well, you're still doing a `map`, so yes, you still need a `.map`
<apotheon> kaleido: sure
<apotheon> otherwise you don't get an array as return value
<kaleido> got it, got it. wasn't thinking that through.
<apotheon> This makes me want to work on my dicebot again.
<apotheon> It's old and crusty now, though still very useful.
rippa has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<apotheon> I bet it's full of refactoring opportunities.
<kaleido> heh, i just wanted some way to learn some basic stuff. maybe someday it won't be so basic :D
gendarme has joined #ruby
<apotheon> Writing small, useful tools is a great way to learn.
gendarme has quit [Remote host closed the connection]
TCZ has joined #ruby
gendarme has joined #ruby
ur5us has joined #ruby
<leitz> kaleido, an idea, if you like. I have a project I'm working, on, and am planning to offer to help new Ruby folks learn by forking the project and doing stuff they want.
<leitz> kaleido, the code is at: https://github.com/makhidkarun/ftl_tools and will look very familiar if you play Traveller.
<kaleido> leitz: i'd love to take a shot at it
jintseng has joined #ruby
<leitz> kaleido, if you do d20 games, there's a tutorial on how to mode the code to fit. https://github.com/makhidkarun/ftl_tools/blob/master/docs/customizing.txt
<leitz> mode/mod
dviola has left #ruby ["WeeChat 2.7.1"]
<leitz> I'm pretty sure we could even figure out exploding dice, like 7th Sea.
dviola has joined #ruby
dviola has left #ruby ["WeeChat 2.7.1"]
dviola has joined #ruby
dviola has left #ruby ["WeeChat 2.7.1"]
dviola has joined #ruby
dviola has quit [Quit: WeeChat 2.7.1]
<leitz> For those of you I'm likely to tap for mentoring, here are the notes I wrote from the original project. It goes for 90 days, and mentors play a key role.
* leitz eyes adam12, apotheon, _phaul, and havenwood...
<apotheon> cool
ElFerna has quit [Ping timeout: 240 seconds]
jintseng has quit [Quit: Leaving]
dviola has joined #ruby
ElFerna has joined #ruby
<apotheon> kaleido: I just looked at your code paste and it occurred to me you might want to consider something like this . . .
<apotheon> kaleido: puts "Each Die: #{results.join ', '}"
<apotheon> kaleido: I don't know if you actually want those brackets in there.
<leitz> kaleido, there was a bug in the code I sent earlier. Ruby defaults to integer division, unless at least one of the numbers is a float. This fixes that.
<leitz> printf "Total: %d Rolls: %s Average: %.2f \n" % [results.sum, results.sort.to_s, results.sum.fdiv(results.count)
<leitz> The "fdiv", if I understand havenwood correctly, ensures the result is a float.
<leitz> And there should be a closing "]" on that line.
<leitz> It's late, I'm pooped.
<havenwood> leitz: For your printf line, check out Rubocop's suggestion for named parameters.
<kaleido> thanks both of you
<havenwood> leitz: 3 / 2 #=> 1
<kaleido> apotheon: those brackets were annoying the hell out of me :)
<havenwood> leitz: 3.fdiv(2) #=> 1.4
<leitz> havenwood, most of the time, dividing 3 by 2 gives you 1.5. :)
<havenwood> 1.5, haha
<leitz> Computer rounding error...
<leftylink> no, it was just for large values of 2
TorpedoSkyline has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<leitz> And skinny values of 3
<havenwood> leitz: But, the Integer#/ method returns a rounded Integer, while Integer#fdiv returns a Float.
<apotheon> I sometimes feel like I want to embark on an ambitious quest to write fractional math tools for every language I use without dealing with IEEE 754 floating point numbers.
<havenwood> I don't much care for Floats.
<havenwood> I don't tend to use them at all.
<havenwood> Or, at least as little as possible.
<apotheon> Yeah, I try to stay away from built in floats, primarily thanks to IEEE 754.
ElFerna has quit [Ping timeout: 258 seconds]
<havenwood> leitz: Compare with: 3/2r
<havenwood> &>> 3/2r
<rubydoc> # => (3/2) (https://carc.in/#/r/8pvi)
<apotheon> I love rational numbers.
<havenwood> They're so... Rational.
<apotheon> INDEED
<kaleido> hardly ever lose their tempers
ElFerna has joined #ruby
<leitz> I've eaten a lot of fast food in my life; I float.
<apotheon> only misplace their tempers
troulouliou_div2 has quit [Quit: Leaving]
cschneid_ has quit [Ping timeout: 256 seconds]
dionysus69 has quit [Quit: dionysus69]
cschneid has joined #ruby
noboruma has quit [Remote host closed the connection]
al3xandr0s has joined #ruby
gendarme has quit [Quit: gendarme]
caterfxo has quit [Quit: leaving]
_phaul is now known as phaul
bsdbandit-01 has quit [Ping timeout: 268 seconds]
oz has quit [Quit: EOF]
NODE has quit [Quit: changing servers]
NODE has joined #ruby
ElFerna has quit [Ping timeout: 265 seconds]
oz has joined #ruby
lightstalker has joined #ruby
fluxAeon has quit [Ping timeout: 258 seconds]
ur5us has quit [Quit: Leaving]
pupsikov has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us has joined #ruby
fluxAeon has joined #ruby
fluxAeon has quit [Ping timeout: 255 seconds]
fluxAeon has joined #ruby
bsdbandit-01 has joined #ruby
lightstalker has quit [Ping timeout: 256 seconds]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
lightstalker has joined #ruby
<phaul> there is the question of how one represent irrationals precisely (without rounding errors). Then you basically arrive at symbolic math systems like wolfram mathematica is.. whether that's needed in a general purpose language like ruby is probably questionable.
shokohsc has quit [Quit: The Lounge - https://thelounge.chat]
<phaul> s/is//
shokohsc has joined #ruby
<phaul> I'm not sure if there is an improvement on floats...
TCZ has quit [Quit: Leaving]
TCZ has joined #ruby
pupsikov has joined #ruby
drincruz has quit [Ping timeout: 260 seconds]
markong has joined #ruby
markoong has quit [Ping timeout: 268 seconds]
pupsikov has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
impermanence has quit [Remote host closed the connection]
cahoots has joined #ruby
<havenwood> phaul: I kinda like what langs like Raku do, where Float is an option but a literal like `4.2` is a Rational by default.
cliluw has quit [Read error: Connection reset by peer]
<havenwood> 4.2.^name #=> Rat
<phaul> interesting approach havenwood
<cahoots> hi, i'm on ruby 2.7.0, installed via homebrew, and osx catalina, and vim bindings don't work. i've tried editing .editrc and .inputrc, but still no dice. any ideas?
cliluw has joined #ruby
ElFerna has joined #ruby
<havenwood> phaul: I've wished the same for Ruby, just since I personally don't have space needs for floating points so I'd rather have a rational under the hood for decimal numbers.
jmcgnh has quit [Read error: Connection reset by peer]
<apotheon> havenwood: Too bad I'd have to use Raku to use Raku.
bsdbandit-01 has quit [Ping timeout: 268 seconds]
<apotheon> cahoots: I have no idea.
jmcgnh has joined #ruby
<phaul> still it's pretty basic to calculate the area of a circle with radius 1, then all attempts to keep it precise and get a number rather than a formula out fall short
ElFerna has quit [Ping timeout: 240 seconds]
orbyt_ has joined #ruby
yokel has quit [Ping timeout: 265 seconds]
<phaul> but I also like this rational by default approach
yokel has joined #ruby
al3xandr0s has left #ruby ["Leaving"]
TCZ has quit [Quit: Leaving]
sergioro has joined #ruby
ldepandis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cschneid has quit [Ping timeout: 240 seconds]
cschneid has joined #ruby