adam12 changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.2, 3.0.4, 2.7.6: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ | Logs: https://libera.irclog.whitequark.org/ruby/
KaitoDaumoto has joined #ruby
<FullMetalStacket> Heyho folks! Back again, this time with a proper IRC client :-)
<FullMetalStacket> def greet(name)
<FullMetalStacket> I am having the same problem again and again and want to understand the basic principle so that once and for good I understand what I am actually doing :-)
<FullMetalStacket> options = ["Hello", "Hi", "Ohai", "ZOMG"]
<FullMetalStacket> options.each { |o| "#{o}, #{name}! " }
<FullMetalStacket> end
<FullMetalStacket> greet("Ada")
<FullMetalStacket> Expected: Hello Ada! , Hi Ada! , Ohai Ada! , ZOMG Ada!
Rounin has quit [Ping timeout: 268 seconds]
<FullMetalStacket> Received: ["Hello", "Hi", "Ohai", "ZOMG"]
<FullMetalStacket> Now, there is something obviously wrong, but what puzzles me most, is that if I try to debug this on IRB by adding a print
<FullMetalStacket> options.each { |o| print "#{o}, #{name}! " }
<FullMetalStacket> I get this:
<FullMetalStacket> Hello, Peter! Hi, Peter! Ohai, Peter! ZOMG, Peter! => ["Hello", "Hi", "Ohai", "ZOMG"]
<FullMetalStacket> So obviously the code is doing what I want it to do when it prints it to the interface but yet internally returns something else. Why is that?
<bougyman> FullMetalStacket: you got the return value of #each, whic is the original thing you iterated on.
<bougyman> use #map instead of #each to return the mutated set.
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<bougyman> options.map { |o| "#{o}, #{name}" }
grokify has joined #ruby
<bougyman> => %w{Hello Hi Ohai ZOMG}.map { |hi| "#{hi}, bougyman!" }
<FullMetalStacket> I see. so actually my each expression does nothing at all. only if i add the print to it it actually does something, but only that, which is printing, without actually returning anything new, correct? can i add something to it so to return the new stuff?
<bougyman> FullMetalStacket: it does exactly what you tell it to in the block. It simply returns the entries of the enumerable as a return value.
<FullMetalStacket> or cant i make this happen with each at all and always need to go with map? (thanks for the solution!)
<bougyman> Yes, you want map.
<bougyman> ruby iterators take some getting used to. But the Enumerable documentation is pretty complete.
<bougyman> That's where most of these methods are going to be documented.
<FullMetalStacket> ok great i will check that out!
grokify has quit [Ping timeout: 240 seconds]
white_magic has joined #ruby
<FullMetalStacket> Works like a charm now, thank zou @bougyman!
<caleb> it's the difference between "for each item I want to do something" (each) and
<caleb> "for each item give me a new item" (map)
<bougyman> ^ This
smp_ has joined #ruby
smp_ is now known as smp
<FullMetalStacket> @caleb Thanks for this explanation!
<FullMetalStacket> bougyman @enumerable doc: is this the best place to read it up or are there more comprehensive docs that you could recommend? https://rubyapi.org/3.1/o/enumerable
<bougyman> That's the one
<FullMetalStacket> ok great thank you!
<bougyman> Of course you can find blog posts going into details of various use cases, but that's the authority :)
<FullMetalStacket> got it
white_magic has quit [Quit: Client closed]
<adam12> FullMetalStacket: One interesting bit about Enumerable that gives it a super power is it can be chained. So you can build up a collection of transformations.
Guest2533 has joined #ruby
goldfish has quit [Ping timeout: 240 seconds]
<FullMetalStacket> @adam12 Yes, absolutely beautiful!
grokify has joined #ruby
grokify has quit [Ping timeout: 256 seconds]
<caleb> I did a dastardly thing to chain things
<caleb> pipe(Alphabet) | Reverse | Upcase
<caleb> as valid ruby
<caleb> I'd never put that in prod tho
markong has quit [Ping timeout: 256 seconds]
grokify has joined #ruby
grokify has quit [Ping timeout: 240 seconds]
<FullMetalStacket> would be great to have it in mainline as I know to use bash pipes well, at least better, than currently ruby :-)
<FullMetalStacket> I just painfully realize that web client that libera.chat provided is so much superior and much more modern and fresh compared to the the IRC client I chose (Quassel IRC) that I think i will continue my search to find another one :-)
Guest2533 has quit [Quit: Client closed]
howdoi has quit [Quit: Connection closed for inactivity]
FullMetalStack has joined #ruby
<FullMetalStack> sdfgsd
<FullMetalStack> sdfgsdfg
<caleb> sdfgsdfg
<FullMetalStacket> shit sorry :-)
FullMetalStack has quit [Quit: Konversation terminated!]
finsternis has quit [Read error: Connection reset by peer]
ur5us has quit [Quit: Leaving]
grokify has joined #ruby
desnudopenguino1 has joined #ruby
ur5us has joined #ruby
grokify has quit [Ping timeout: 260 seconds]
desnudopenguino has quit [Ping timeout: 260 seconds]
desnudopenguino1 is now known as desnudopenguino
perrierjouet has quit [Quit: WeeChat 3.7.1]
grokify has joined #ruby
perrierjouet has joined #ruby
moldorcoder7 has quit [Ping timeout: 256 seconds]
grokify has quit [Ping timeout: 260 seconds]
FullMetalStacker has joined #ruby
grokify has joined #ruby
grokify has quit [Ping timeout: 268 seconds]
ur5us has quit [Ping timeout: 256 seconds]
FullMetalStacker has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
grokify has joined #ruby
grokify has quit [Ping timeout: 260 seconds]
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
Y05hito__ has quit [Quit: Leaving]
grokify has joined #ruby
<FullMetalStacket> Hi all! I stumbled about some notation I can hardly find anythig about to fully understand what is happening. A case statement that receives an array of names and depending to the amount of names, creates messages with some names plus the amount of names. someone solved this very elegantly with %s and %d.
<FullMetalStacket> case names.size
<FullMetalStacket> when 3 then "%s, %s and %s like this" % names
<FullMetalStacket> else "%s, %s and %d others like this" % (names[0,2] + [names.size-2])
<FullMetalStacket> question: what are those %s and %d and how can someone use them and when? I understand what is happening but I don't know why/ what this actually is that I am looking at.
<grawity> they're string templates in the style of C printf() function
grokify has quit [Ping timeout: 240 seconds]
<grawity> (I've never seen them in ruby, but they used to be very common in python, with the `template % params` syntax and all)
<leftylink> pandabot: ri String#%
<leftylink> as you can see, it's all there in the documentation
<sam113101> why is it called case instead of switch?
<FullMetalStacket> @grawity thanks! @leftylink: i see, I had searched for %s and %d but this had zero hits, but your link forwarded me hereto and now I have that list I was searching for, thank you very much! https://ruby-doc.org/core-3.0.1/Kernel.html#method-i-sprintf
<FullMetalStacket> @leftylink what is that pandabot thing you used??
cartdrige has joined #ruby
ur5us has joined #ruby
<leftylink> well, pandabot was originally made in the service of pink pandas, but over time it took on other needs as well
<leftylink> so we can only conclude that this is one of those aforementioned "other needs"
Linux_Kerio has joined #ruby
grokify has joined #ruby
grokify has quit [Ping timeout: 240 seconds]
<FullMetalStacket> i see but i mean in generally what is it :-) you just entered the command and it fetched the documentation??
D_A_N has quit [Quit: leaving]
<leftylink> well, we can surmise from looking at it that it's text transformation with only a few rules. there doesn't seem to be much special logic to it
<leftylink> now, the command is ri because it's named after the command-line tool ri, which is distributed with rdoc
ur5us has quit [Ping timeout: 260 seconds]
FullMetalStacket has quit [Read error: Connection reset by peer]
cartdrige has quit [Ping timeout: 260 seconds]
kerunaru has joined #ruby
Furai has quit [Quit: WeeChat 3.7.1]
Sankalp has quit [Ping timeout: 268 seconds]
Sankalp has joined #ruby
FullMetalStacker has joined #ruby
<FullMetalStacker> pandabot: ri Array#map
<FullMetalStacker> hm what was wrong? :-)
<FullMetalStacker> pandabot: ri String#%
Furai has joined #ruby
Sankalp has quit [Ping timeout: 252 seconds]
dviola has joined #ruby
walez has joined #ruby
Sankalp has joined #ruby
or2b has joined #ruby
ur5us has joined #ruby
lutrinus has joined #ruby
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
grokify has joined #ruby
grokify has quit [Ping timeout: 260 seconds]
aighearach has joined #ruby
walez has quit [Quit: Leaving]
dionysus69 has joined #ruby
some14u has joined #ruby
ur5us has quit [Ping timeout: 260 seconds]
jvalleroy has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
teclator has joined #ruby
jvalleroy has joined #ruby
moldorcoder7 has joined #ruby
leftylink has quit [Read error: Software caused connection abort]
leftylink has joined #ruby
desnudopenguino has quit [Read error: Connection reset by peer]
desnudopenguino has joined #ruby
niv has quit [Quit: Powered by LunarBNC: https://LunarBNC.net]
some14u is now known as joto
FullMetalStacker has quit [Remote host closed the connection]
otisolsen70 has joined #ruby
sam113101 has quit [Quit: WeeChat 3.6]
or2b has quit [Quit: Leaving]
joto has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cartdrige has joined #ruby
or2b has joined #ruby
niv has joined #ruby
supay has joined #ruby
cartdrige has quit [Quit: Leaving]
otisolsen70 has quit [Quit: Leaving]
otisolsen70 has joined #ruby
Tomte has joined #ruby
FullMetalStacker has joined #ruby
niv has quit [Quit: Powered by LunarBNC: https://LunarBNC.net]
markong has joined #ruby
cek has joined #ruby
niv has joined #ruby
cartdrige has joined #ruby
sam113101 has joined #ruby
alexherbo2 has joined #ruby
niv has quit [Quit: Powered by LunarBNC: https://LunarBNC.net]
D_A_N has joined #ruby
alexherbo2 has quit [Remote host closed the connection]
niv has joined #ruby
alexherbo2 has joined #ruby
crax23 has joined #ruby
cartdrige has quit [Ping timeout: 252 seconds]
crax23 has quit [Ping timeout: 260 seconds]
Linux_Kerio has quit [Ping timeout: 256 seconds]
wand has quit [Remote host closed the connection]
peirik__ has joined #ruby
wand has joined #ruby
sam113101 has quit [Quit: WeeChat 3.6]
<peirik__> Can anyone explain why certain gems are missing on 'bundle exec jekyll build' after 'bundle install' says it installs them? Full console paste here: http://pastie.org/p/7a9sZSQSx4Dya1zo9fON8h
cartdrige has joined #ruby
<bougyman> Can you show the Gemfile, please?
peirik__ has quit [Ping timeout: 260 seconds]
peirik__ has joined #ruby
<cxl> Hi, I have a Document model which has many Pages. Pages are processed using ActiveJob and they eventually all have Page#current_state == "processed". What is an elegant and efficient way for Document to find out if all its Pages are "processed" and return `true` for Document#processed ?
<cxl> peirik__: are you using rvm?
peirik__ has quit [Ping timeout: 256 seconds]
kerunaru has quit [Quit: leaving]
<adam12> FullMetalStacker: pandabot only responds to leftylink. We should add the `ri` functionality to ruby[bot] tho, since it's handy.
<adam12> cxl: Elegant is pages.all? { |page| page.processed? }
<adam12> cxl: Efficient might be a counter on Document for # of pages, and a counter on Document for # of processed pages. Have each page report it's processed state to Document.
<cxl> adam12: Thanks
polishdub has quit [Remote host closed the connection]
eddof13 has joined #ruby
<adam12> And obviously for the second one, Document#processed is total_pages == processed_pages, to wrap everything up.
<adam12> or rather, total_page_count == processed_page_count
<adam12> I don't think I'd burn the processed_pages name on this.
some14u has joined #ruby
<cxl> it makes sense, yes
eddof13 has quit [Quit: My MacBook Air has gone to sleep. ZZZzzz…]
sam113101 has joined #ruby
<caleb> morning
<adam12> morning!
polishdub has joined #ruby
crax23 has joined #ruby
cartdrige has quit [Ping timeout: 240 seconds]
<caleb> I can't tell if I'm becoming more curmudgeonly or if I just don't like GraphQL over REST
<caleb> I've been writing sorbet typed graphql apis for a couple years now and I just, don't enjoy it
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<adam12> I don't care for GraphQL either.. and tbh, if the API isnt' public facing, I don't want REST either.
<adam12> I see so many internal API's use REST, and the bike shedding about PUT/PATCH/POST/DELETE/whatever becomes unbearable. I've seen teams not using anything outside of GET/POST to starve the bike shedding.
<adam12> I'd rather we just use JSON-RPC, then it can be transport agnostic.
<caleb> I think most places I've worked at have used a message broker of some sort to facilitate internal communication
<caleb> REST for internal stuff seems overkill and more overhead
<adam12> I echo your sentiment tho. Sometimes I feel like I'm the old man yelling at the kids to get off my lawn.
c10l6 has joined #ruby
c10l has quit [Ping timeout: 256 seconds]
c10l6 is now known as c10l
cage has joined #ruby
peirik__ has joined #ruby
Y05hito__ has joined #ruby
peirik_ has joined #ruby
crax23 has quit [Ping timeout: 260 seconds]
peirik__ has quit [Ping timeout: 240 seconds]
grokify has joined #ruby
pvalenta has quit [Quit: ZNC - https://znc.in]
peirik__ has joined #ruby
infinityfye has joined #ruby
grokify has quit [Ping timeout: 252 seconds]
peirik_ has quit [Ping timeout: 252 seconds]
dionysus69 has quit [Ping timeout: 260 seconds]
cartdrige has joined #ruby
Y05hito__ has quit [Ping timeout: 268 seconds]
Thanzex32 has quit [Ping timeout: 246 seconds]
pvalenta has joined #ruby
dionysus69 has joined #ruby
peirik__ has quit [Ping timeout: 252 seconds]
grokify has joined #ruby
grokify has quit [Ping timeout: 256 seconds]
lutrinus has quit [Ping timeout: 260 seconds]
finsternis has joined #ruby
alexherbo2 has quit [Remote host closed the connection]
alexherbo2 has joined #ruby
crax23 has joined #ruby
cartdrige has quit [Ping timeout: 256 seconds]
peirik__ has joined #ruby
dionysus69 has quit [Ping timeout: 260 seconds]
Tomte has quit [Read error: Connection reset by peer]
peirik__ has quit [Ping timeout: 256 seconds]
supay has quit [Quit: Connection closed for inactivity]
grokify has joined #ruby
pvalenta has quit [Quit: ZNC - https://znc.in]
grokify has quit [Ping timeout: 260 seconds]
___nick___ has joined #ruby
pvalenta has joined #ruby
alexherbo2 has quit [Ping timeout: 260 seconds]
infinityfye has quit [Quit: Leaving]
crankharder has joined #ruby
Linux_Kerio has joined #ruby
pvalenta has quit [Quit: ZNC - https://znc.in]
peirik__ has joined #ruby
pvalenta has joined #ruby
markong has quit [Ping timeout: 256 seconds]
peirik__ has quit [Ping timeout: 256 seconds]
peirik__ has joined #ruby
Y05hito__ has joined #ruby
peirik__ has quit [Ping timeout: 256 seconds]
crax23 has quit [Ping timeout: 256 seconds]
Thanzex32 has joined #ruby
keb has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
_ht has joined #ruby
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
Y05hito__ has quit [Ping timeout: 260 seconds]
r0bby has quit [Ping timeout: 268 seconds]
jposer has quit [Ping timeout: 255 seconds]
r0bby has joined #ruby
jposer has joined #ruby
r0bby has quit [Max SendQ exceeded]
jposer has quit [Ping timeout: 240 seconds]
Linux_Kerio has quit [Quit: Konversation terminated!]
r0bby has joined #ruby
grvgr has quit [Ping timeout: 252 seconds]
r0bby has quit [Max SendQ exceeded]
r0bby has joined #ruby
jposer has joined #ruby
grvgr has joined #ruby
r0bby has quit [Max SendQ exceeded]
jposer has quit [Max SendQ exceeded]
r0bby has joined #ruby
r0bby has quit [Max SendQ exceeded]
jposer has joined #ruby
r0bby has joined #ruby
jposer has quit [Max SendQ exceeded]
r0bby has quit [Max SendQ exceeded]
jposer has joined #ruby
jposer has quit [Max SendQ exceeded]
jposer has joined #ruby
jposer has quit [Max SendQ exceeded]
jposer has joined #ruby
cartdrige has joined #ruby
alexherbo2 has joined #ruby
otisolsen70 has quit [Quit: Leaving]
some14u has joined #ruby
r0bby has joined #ruby
ur5us has joined #ruby
cage has quit [Quit: rcirc on GNU Emacs 27.1]
sixthousand has joined #ruby
<sixthousand> good afternoon
gproto23 has joined #ruby
some14u is now known as joto
___nick___ has quit [Ping timeout: 248 seconds]
gproto23 has quit [Remote host closed the connection]
gproto23 has joined #ruby
_ht has quit [Remote host closed the connection]
sixthousand has left #ruby [#ruby]
alexherbo2 has quit [Remote host closed the connection]
joto has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
otisolsen70 has joined #ruby
or2b has quit [Quit: Leaving]
markong has joined #ruby
RetroPunk has quit [Quit: ZNC 1.8.2+deb2build5 - https://znc.in]
RetroPunk has joined #ruby
crankharder has quit [Ping timeout: 268 seconds]
some14u is now known as joto
cryptkeeper has quit [Quit: Connection closed for inactivity]
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
cryptkeeper has joined #ruby
otisolsen70 has quit [Quit: Leaving]
grokify has joined #ruby
grokify has quit [Ping timeout: 256 seconds]
justache is now known as justGrit