<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>
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…]
<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.
<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]
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>
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]
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
<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.