<rapha>
how do you write something yourself that takes a block, such as Array#each? specifically, I want a method called walk_tree_for_keys(/some_regex/){|value| here_i_can_do_something_based_on_the_value_of_each_key_that_matched_the_regex} ... would that work with yield() somehow, inside of `def walk_tree_for_keys`?
akem has joined #ruby
meinside has quit [Quit: Connection closed for inactivity]
drincruz has joined #ruby
<leftylink>
so maybe it is best to answer shortly and say "yes, yield. try making and running a short example to prove to yourself that this works". I think that would be appropriate if we are *not* including the feature "if no block is given, instead return an enumerator" which is a common feature of many of those methods in the standard library
<leftylink>
if that feature is needed, then... more study is needed
<leftylink>
(more study by me, since I do not know what they do to do that)
<ruby[bot]>
ruby428: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
<adam12>
ruby428: what do you mean?
<ruby428>
I'm creating an enumerator of timestamps in the BST timezone, yet the enumerator.next method returns a timestamp in UTC time zone
<ruby428>
That seems like incorrect behaviour
<adam12>
ruby428: I'm _suspicious_ that this might be a Rails bug.
<adam12>
Actually, hmm.
<rapha>
ruby[bot]: but what if someone doesn't have a GitHub account and doesn
<rapha>
't want one either.
<rapha>
Well, not expecting much of an answer from a bot. But wondering what the preferred place would then be.
<ruby428>
I am running that snippet in a Rails environment by the way
<adam12>
ruby428: Some ActiveSupport date methods mutate the receiver, which is what I thought was happening here.. but you don't re-use the same object so I'm maybe a bit lost.
<adam12>
ruby428: Out of curiosity, what if you didn't use ActiveSupport methods? y << Time.now - (n * 3600)
<adam12>
(they mutate the receiver but it's not obvious that they do so)
<ruby428>
Ah, If I change it to what you suggested, it returns both timestamps in BST
<ruby428>
so it works as I'd expect
dhollinger has quit [Ping timeout: 260 seconds]
<adam12>
ruby428: So I think ActiveSupport is indeed mutating something...
<adam12>
Or the time zone is lost on the second call.. mysteries.
bmurt has quit [Ping timeout: 258 seconds]
<ruby428>
Yea the timezone is getting lost
<adam12>
ruby428: What happens if you use Time.zone.now - (n * 3600)
<ruby428>
If I put the setting of the timezone inside the enumerator, it works too
<adam12>
Oh it does? Hmm
alfiemax has quit [Remote host closed the connection]
dhollinger has joined #ruby
<ruby428>
Why would #first behave differently to #next
<ruby428>
Something to do with Fibers maybe? I don't know much about them though
<adam12>
ruby428: What happens if you output Time.zone between calls?
<adam12>
ruby428: In theory, #first or #next wouldn't matter here. What if you do #last instead of #next?
alfiemax has joined #ruby
<ruby428>
The Time.zone doesn't change between calls
<ruby428>
hmm Enumerator doesn't implement #last
<adam12>
Oh it doesn't? Huh. News to me.
<adam12>
What about coercing to array?
<ruby428>
Coercing to an array does keep the BST timezone
<ruby428>
so it's really just the 'next' method that's causing problems...
joshcom has joined #ruby
<adam12>
What Ruby version?
<adam12>
And did using Time.zone.now have any change?
<ruby428>
2.6.5
<ruby428>
Time.zone.now suffers from the same problem
<adam12>
Can you try #peek too? See if we can narrow down if it's actually #next.
<ruby428>
Peek has same problem
alfiemax has quit [Remote host closed the connection]
<adam12>
And without an enumerator it's fine? [1, 2].each {|n| puts n.hours.from_now }
<ruby428>
Yup
<ruby428>
It seems that #each returns timestamps with the correct zone too
joshcom has quit [Remote host closed the connection]
<adam12>
I mean, I guess it might be Fiber related..
<adam12>
Rails stores the timezone in a Thread.current
<adam12>
Could the fiber be resumed in another thread? That I'm not really sure of.
<ruby428>
That's what I'm wondering. But why would it use a fiber for next/peek, but not 'each/to_a'?>
<ruby428>
ah wait, I guess the fiber is used when there will be stop/starting expected
impermanence has quit [Ping timeout: 240 seconds]
<adam12>
Yeah. In the C source, next definitely yields the fiber.
<rapha>
havenwood: thank you for the links! i read both, but currently my eye (had a splinter in it and required drilling into the cornea) is hurting a little much. hopefully within an hour or two i can get back to this.
ChmEarl has quit [Quit: Leaving]
<havenwood>
rapha: Ouch. Feel better!
sagax has joined #ruby
howdoi has joined #ruby
dead10cc has joined #ruby
cthulchu has quit [Read error: Connection reset by peer]
cthulchu has joined #ruby
chouhoulis has joined #ruby
supercoven_ has quit [Ping timeout: 272 seconds]
Swyper has quit [Remote host closed the connection]
chouhoulis has quit [Ping timeout: 272 seconds]
dead10cc has quit [Ping timeout: 258 seconds]
chouhoulis has joined #ruby
alexherbo22 has joined #ruby
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo22 is now known as alexherbo2
lightstalker has quit [Remote host closed the connection]
dead10cc has joined #ruby
lightstalker has joined #ruby
davispuh has joined #ruby
alexherbo25 has joined #ruby
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo25 is now known as alexherbo2
BSaboia has joined #ruby
schne1der has quit [Ping timeout: 256 seconds]
Swyper has joined #ruby
alfiemax has quit [Remote host closed the connection]
duckpuppy has quit [Remote host closed the connection]
duckpuppy has joined #ruby
duderonomy has quit [Ping timeout: 240 seconds]
schne1der has joined #ruby
cyrus_mc_ has quit [Quit: Connection closed]
ramfjord has joined #ruby
rippa has joined #ruby
schne1der has quit [Ping timeout: 272 seconds]
dead10cc has left #ruby [#ruby]
zacts has quit [Ping timeout: 272 seconds]
Swyper has quit [Remote host closed the connection]
Sauvin has quit [Read error: Connection reset by peer]
zacts has joined #ruby
duderonomy has joined #ruby
brunosaboia_ has joined #ruby
TCZ has joined #ruby
BSaboia has quit [Ping timeout: 272 seconds]
vondruch_ has joined #ruby
brunosaboia_ has quit [Ping timeout: 256 seconds]
zacts has quit [Quit: leaving]
vondruch has quit [Ping timeout: 264 seconds]
vondruch_ is now known as vondruch
infinityfye has quit [Quit: Leaving]
CrazyEddy has quit [Ping timeout: 260 seconds]
mjacob has quit [Ping timeout: 260 seconds]
duderonomy has quit [Ping timeout: 256 seconds]
punnie has quit [Quit: Connection closed for inactivity]
Swyper has quit [Remote host closed the connection]
Swyper has joined #ruby
tty1 has joined #ruby
<tty1>
hi, bit of a ruby noob here despite having done quite a bit of mashing the keyboard to code in it anyway... but i need help with something and i may have something backwards in how im approaching this
<tty1>
Is there a way to update the gem lockfile but without having the bundler version strictly defined?
r3my has quit [Ping timeout: 240 seconds]
s2013 has joined #ruby
fowl has quit [Ping timeout: 240 seconds]
integral has quit [Read error: Connection reset by peer]
peteretep has quit [Read error: Connection reset by peer]
redlegion has quit [Read error: Connection reset by peer]
Atro has quit [Ping timeout: 240 seconds]
kozowu has quit [Write error: Connection reset by peer]
afisher has quit [Read error: Connection reset by peer]
AutomationD has quit [Read error: Connection reset by peer]
Fenhl has quit [Read error: Connection reset by peer]
peteretep has joined #ruby
rann has quit [Read error: Connection reset by peer]
itok has quit [Write error: Connection reset by peer]
fowl has joined #ruby
dputtick has quit [Write error: Connection reset by peer]
<AndreYuhai>
What's wrong with this one? Basically words in the array "words" should be grouped based on their chars. order doesn't matter
<AndreYuhai>
Why some words are grouped together even though they have different chars
<AndreYuhai>
this got me so annoyed
tty1 has quit [Quit: WeeChat 2.9]
TCZ has joined #ruby
ramfjord has quit [Ping timeout: 264 seconds]
bmurt has joined #ruby
BTRE has joined #ruby
ramfjord has joined #ruby
<leftylink>
oh, phew, I thought google was going to ask me for a captcha to even view that
<leftylink>
which might have made me ragequit
<leftylink>
does anyone know if there's a raw version of repl.it that doesn't have so much js?
<leftylink>
(yes the captcha screen did pop up for a brief instant, but it didn't come up again on a refresh)
s2013 has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<leftylink>
wouldn't this be easier to debug if the included the letters that each group is supposedly associated with? then it would be easy to see by hand whether each word in the group should be there or not, by comparing it to the letters.
<AndreYuhai>
leftylink, I can send it on dpaste though
<leftylink>
after all this is just reinventing the wheel of group_by, and group_by *would* provide this information
<AndreYuhai>
adam12, the expected output should be each words having the same characters grouped in the same array. But what I am asking is why in my code some of the words are grouped together even though they don't have the same chars
<AndreYuhai>
I will share the outpu
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<AndreYuhai>
Iambchop, I didn't get what that means sorry my brain can't process anything now. :D
<leftylink>
I understand I'm being difficult, since my answer to "what is wrong?" has been "here's how you find out what is wrong" instead of "here is what is wrong", but for some reason I just didn't think saying "here is what is wrong" was the right move for this conversation. if you disagree, I apologise, let me know and I'll recuse myself from the conversation
<leftylink>
I never mean to intentionally cause frustration so if I ever unintentionally do so I would like to apologise
<AndreYuhai>
leftylink, oh no that's okay I was trying to do what you said but for some reason when I copy paste this code into pry it says groups can't be found haha
stryek has quit [Quit: Connection closed for inactivity]
<Iambchop>
AndreYuhai: in the suggested [s, group] look at that group (it's near the end of the list, easier to find)
<Iambchop>
(that group with the 'iig' I mean)
<AndreYuhai>
Once I can run the code I shared, I will hahah.
Scient has quit [Ping timeout: 246 seconds]
drincruz has quit [Ping timeout: 265 seconds]
<adam12>
AndreYuhai: I figured it out but I don't really have an answer for you...
<adam12>
Actually
<adam12>
I lie
<adam12>
It looks right but it's not. I see one error immediately.
<AndreYuhai>
when I run it, what I get is: [["b", "b", "f"], ["bgf", "sbf", "fxb", "fyb", "bbf", "bfh", "bef", "bgf", "bmf", "bfy"]]
<AndreYuhai>
So the s is ["b", "b", "f"]
<leftylink>
cool
<AndreYuhai>
and the words are whatever is left
<AndreYuhai>
so how can this make (s - words.chars).empty?
<AndreYuhai>
I don't get what's wrong with my code
<leftylink>
so let's see why bgf gets included in the ["b", "b", "f"] group huh
<leftylink>
words.chars would be ["b", "g", "f"] would it not?
<AndreYuhai>
yes
<AndreYuhai>
and s - word.chars would not be empty in that case
kent\n has quit [Quit: going offline a few days for house fumigation]
<AndreYuhai>
So I didn't know how that works then
<AndreYuhai>
I thought it would return g
<AndreYuhai>
Sad
Swyper has quit [Read error: Connection reset by peer]
<Iambchop>
not sad; that's a reasonable guess
TCZ has quit [Ping timeout: 264 seconds]
Swyper has joined #ruby
<Iambchop>
for that ooeration w/o knowing
<Iambchop>
and now you know :-)
<AndreYuhai>
But there is a method that does it maybe? I am not sure but I kind of remember you could do it both ways
<AndreYuhai>
And I spent more than an hour on this haha.
TCZ has joined #ruby
Mia has quit [Read error: Connection reset by peer]
<AndreYuhai>
anyway thank you all Iambchop adam12 leftylink for helping me find out what was wrong. :)
<leftylink>
well, it is easy to agree that ["b", "g", "f"] - ["b", "b", "f"] == ["g"]. I am strictly just answering the question of whether that was possible, with no particular comment on whether it is the way to go for this problem
gueorgui has joined #ruby
<leftylink>
I need to make a habit of saying such a comment both when it is and when it is not the way to go, otherwise it's a tell for whether it actually is if I only say it in one of the two situations
<AndreYuhai>
leftylink, I didn't know about group_by either. I guess group_by { |w| w.chars.sort } would easily solve this. Not sure though whether that takes char count into account as well
<adam12>
tbh I'm surprised subtracting the arrays didn't work, but in all honestly I'm not sure I've ever had to try.
gueorgui_ has quit [Ping timeout: 260 seconds]
s3nd1v0g1us has joined #ruby
s3nd1v0g1us has quit [Client Quit]
<AndreYuhai>
I just thought it would work and didn't even try it on pry to see what it does. I think I was so sure that it does what I thought it would ahaha. But it didn't ¯\_(ツ)_/¯
jenrzzz has quit [Ping timeout: 260 seconds]
bamdad has quit [Ping timeout: 240 seconds]
bamdad has joined #ruby
s3nd1v0g1us has joined #ruby
<leftylink>
happened to me many times!
<leftylink>
the problem being in somewhere where I hadn't suspected it to be
akem has joined #ruby
<leftylink>
usually I'll have a good sense of where I *expect* the problem to be. and then sometimes the expectations are right. but sometimes they are wrong
<leftylink>
gotta reevaluate those expectations sometimes I guess
akem_ has quit [Ping timeout: 260 seconds]
drincruz has joined #ruby
<AndreYuhai>
I was printing all the groups but couldn't figure out why it was wrong. Never thought about the "-" operator so I wasted my time printing stuff and then it got me frustrated so I asked it here and thanks to you all, now I know what exactly "-" operator does. :D