havenwood changed the topic of #ruby to: Ruby 3.2.2, 3.1.4, 3.3.0-preview1: https://www.ruby-lang.org | Rules: https://ruby-community.com | Logs: https://libera.irclog.whitequark.org/ruby
hightower4 has joined #ruby
hightower3 has quit [Ping timeout: 245 seconds]
reset has quit [Quit: reset]
leah2 has quit [Ping timeout: 246 seconds]
<johnjaye> hmm. what am i doing wrong. i'm trying to measure time of some code
<johnjaye> i'm doing something like Benchmark.measure { 10**x.times { //code// sleep(1) } }
<johnjaye> but the sleep(1) call is ignored
<adam12> johnjaye: Ignored how?
<adam12> johnjaye: From the measurement result or not called at all?
<adam12> Maybe you want Benchmark.realtime
<johnjaye> i don't think it's being called at all.
<johnjaye> i put sleep(1) and ran it 1000 times and it finishes instantly
<johnjaye> is it the "times" thing that makes it ignored?
<johnjaye> hmm. benchmark.realtime just returns the last entry of the struct that measure was returning already
<johnjaye> changing the .times to a range (1..10**x).each didn't change it either
<adam12> johnjaye: Hard to say. Show all your code?
<adam12> It looks accurate.
<adam12> Benchmark.realtime { (10**1).times { sleep 1 } } # => 10.008379000006244
<johnjaye> hmm, strange. it works on the irb prompt
<johnjaye> oh wait you used the number itself not a range
<johnjaye> wait that works too on irb.
<johnjaye> now i'm really confused
<johnjaye> i copied the code from the rb file to the irb prompt and it behaves completely differently
<johnjaye> i guess i'm missing something obvious
<johnjaye> does sleep behave differently depending on if it's invoked at the prompt or not?
<adam12> Shouldn't.
konsole20 is now known as konsolebox
<adam12> But `sleep` isn't necessarily sleep...
<adam12> are you using Async or anything?
<johnjaye> idk.
<adam12> Is this in an app? with a Gemfile? or just a plain .rb file somewhere?
<johnjaye> just an rb file.
<adam12> Should be fine then. I'd have to see code.
<johnjaye> ok it's something to do with using x instead of the number
<johnjaye> as in i pass in 1 on the command line for x in the 10**x
<johnjaye> changing the 'x' to a '1' makes it work fine
<johnjaye> does the ** operator not work with variables?
<adam12> It should
<adam12> Do you mean to use ARGV[0] ?
<adam12> It works fine for me, but I need to change ARGV[1] to ARGV[0]
<johnjaye> is argv[0] not the program name?
<johnjaye> apparently not. i thought i checked that earlier.
<johnjaye> my apologies.
<adam12> I think that's a C-ism :P
<johnjaye> oh ok
<johnjaye> in that case i withdraw my apology.
<johnjaye> c is weird
<johnjaye> so i guess ruby doing sensible defaults probably is the reason here
<johnjaye> nil.to_i gives 0
<adam12> That's right
<adam12> If you want it a bit stricter, use the Integer() coercion method
<johnjaye> i didn't know ruby had coercion
<adam12> Integer(ARGV[0])
<johnjaye> or i thought it didn't
<johnjaye> why is Integer(nil) not valid but to_i is.
<adam12> Ruby will try to give you something with the .to_N methods, but it might not be what you want.
<adam12> ie. nil and 0 might be equal to you, or maybe it's not. You'll have to decide.
<johnjaye> by the way google that question it literally says .to_i is coercion
<adam12> same with nil.to_a and []
<adam12> Sure. There's implicit and explicit coercion in Ruby
<adam12> and then there's levels of coercion.
<johnjaye> i.. see
<johnjaye> i googled for an article and the nil.to_i thing is the first example of problems with coercion it shows. heh
<johnjaye> what does 'Kernel' mean again?
<johnjaye> i see it used a lot
Starfoxxes has quit [Ping timeout: 256 seconds]
Starfoxxes has joined #ruby
<ox1eef_> Kernel is a module that's included in the Object class, and provides most of its behavior.
<johnjaye> ah ok
keypresser86 has joined #ruby
brw9 has quit [Quit: The Lounge - https://thelounge.chat]
brw9 has joined #ruby
<johnjaye> is there another way to do a loop in reverse other than downto
<johnjaye> as in 10.downto(5).each { ...
joast has quit [Quit: Leaving.]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
some14u has joined #ruby
keypresser86 has quit []
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
shokohsc51085 has joined #ruby
totoro has joined #ruby
shokohsc5108 has quit [Ping timeout: 256 seconds]
shokohsc51085 is now known as shokohsc5108
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
_ht has quit [Quit: _ht]
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
_ht has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
Argorok has joined #ruby
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
llua has quit [Quit: <Rudolph> shell code is what greycat reads to kids when he tucks them in]
llua has joined #ruby
<ox1eef_> No need for each in that example. 10.downto(5) { ... } is enough. I don't know of many other ways, besides a loop and a counter. Ranges are expected to ascend rather than descend. Eg: (10..5).to_a is probably not what you'd expect.
desnudopenguino1 has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
desnudopenguino has quit [Ping timeout: 248 seconds]
desnudopenguino1 is now known as desnudopenguino
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
<gr33n7007h> johnjaye: 10.step(5, -1) ((10..5)%-1).each, (5..10).reverse_each, (10..5).step(-1).each, 10.downto(5)
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
joedude has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
joedude has quit [Client Quit]
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
A_Dragon has quit [Ping timeout: 615 seconds]
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
totoro has quit [Remote host closed the connection]
totoro has joined #ruby
sts has quit [Ping timeout: 244 seconds]
totoro has quit [Client Quit]
sts has joined #ruby
_ht has quit [Remote host closed the connection]
grenierm has joined #ruby
grenierm has quit [Quit: Client closed]
A_Dragon has joined #ruby
grenierm has joined #ruby
Argorok has quit [Quit: Connection closed for inactivity]
willfish has joined #ruby
___nick___ has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
TomyWork has joined #ruby
shokohsc5108 has quit [Ping timeout: 245 seconds]
shokohsc5108 has joined #ruby
leah2 has joined #ruby
___nick___ has quit [Ping timeout: 250 seconds]
grenierm has quit [Ping timeout: 246 seconds]
MarvelousWololo has quit [Read error: Connection reset by peer]
crespire has quit [Killed (NickServ (GHOST command used by crespire1))]
crespire1 has joined #ruby
bhaak has quit [Ping timeout: 246 seconds]
patrick- has quit [Ping timeout: 252 seconds]
patrick- has joined #ruby
reset has joined #ruby
konsolebox has quit [Ping timeout: 246 seconds]
infinityfye has joined #ruby
tuxcrafter has quit [Quit: Client closed]
bhaak has joined #ruby
desnudopenguino has quit [Read error: Connection reset by peer]
dza has quit [Quit: ]
dza has joined #ruby
shokohsc51083 has joined #ruby
shokohsc5108 has quit [Ping timeout: 252 seconds]
shokohsc51083 is now known as shokohsc5108
sagax has quit [Quit: Konversation terminated!]
dalan03822 has quit [Quit: dalan03822]
dalan03822 has joined #ruby
user23 has joined #ruby
user23 has quit [Remote host closed the connection]
Sankalp has quit [Ping timeout: 246 seconds]
some14u has joined #ruby
some14u has quit [Client Quit]
_whitelogger has joined #ruby
Sankalp has joined #ruby
desnudopenguino has joined #ruby
some14u has joined #ruby
Argorok has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
some14u has quit [Client Quit]
some14u has joined #ruby
some14u has quit [Client Quit]
<adam12> Good morning
some14u has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
eddof13 has joined #ruby
brokkoli_origin has quit [Ping timeout: 250 seconds]
brokkoli_orig has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
some14u has quit [Client Quit]
c10l6 has quit [Ping timeout: 246 seconds]
<johnjaye> can you use ruby in visual studio or vscode
<johnjaye> is "reverse_each" a common thing or only for ranges
MarvelousWololo has joined #ruby
some14u has joined #ruby
eddof13 has quit [Ping timeout: 246 seconds]
<ox1eef_> You can find where a method comes from with Method#owner: [].method(:reverse_each).owner, (1..5).method(:reverse_each).owner, etc.
<ox1eef_> Good morning adam12
<adam12> johnjaye: What do you mean 'use'? Can you 'edit'?
<adam12> ox1eef_: how goes
rvalue has quit [Ping timeout: 248 seconds]
<ox1eef_> All good in the hood, and you?
<adam12> ox1eef_: Not too bad.
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
neshpion has joined #ruby
some14u has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_ht has joined #ruby
willfish has quit [Ping timeout: 245 seconds]
TomyWork has quit [Remote host closed the connection]
<havenwood> johnjaye: Since there's an Enumerable#reverse_each it's quite common. Anything that includes Enumerable supports #reverse_each either through an optimized implementations or Enumerable's default one.
<havenwood> implementation*
<johnjaye> adam12: well. like you'd do with python or perl
<johnjaye> idk if you can use debugger in those languages
<johnjaye> Enumerable is a "mixin", not an actual class? so similar to an interface in java?
grenierm has joined #ruby
<weaksauc_> enumerable is a module
<weaksauc_> which is not a class yes
<weaksauc_> but it is a collection of methods that you can include into your derivative classes so long as you implement each (and maybe one other method i'm forgetting)
<havenwood> johnjaye: Enumerable is a Module but not a Class. Module is a Class. You can ask them.
<havenwood> >> Enumerable.is_a?(Class)
<ruby[bot]> havenwood: # => false (https://carc.in/#/r/fmje)
<havenwood> >> Enumerable.is_a?(Module)
<ruby[bot]> havenwood: # => true (https://carc.in/#/r/fmjf)
<leftylink> pandabot rb Enumerable.class
<pandabot> Module - https://carc.in/#/r/fmjh
<havenwood> Then it gets funny.
<havenwood> >> Class.is_a?(Module)
<ruby[bot]> havenwood: # => true (https://carc.in/#/r/fmji)
<havenwood> >> Module.is_a?(Class)
<ruby[bot]> havenwood: # => true (https://carc.in/#/r/fmjj)
<havenwood> leftylink: Yeah, more straightforward to just ask it its #class.
<havenwood> johnjaye: You can't be a Module and a Class, just one or the other. Classes can inherit from one class and mixin many Modules.
<weaksauc_> you can also have modules that have methods directly on them
grenierm has quit [Quit: Client closed]
caedmon has joined #ruby
willfish has joined #ruby
otisolsen70 has joined #ruby
infinityfye has quit [Ping timeout: 248 seconds]
otisolsen70 has quit [Quit: Leaving]
_ht has quit [Quit: _ht]
<ox1eef_> Those details can be a bit confusing and I'd probably skip them until I'm interested in meta programming. Classes, modules, and mixins are vanilla yoghurt, and a great start to write easy to understand and maintainable Ruby applications.
some14u has joined #ruby
caedmon has quit [Ping timeout: 256 seconds]
willfish has quit [Quit: WeeChat 4.0.2]
willfish has joined #ruby
<johnjaye> oh ok
FetidToot1 has joined #ruby
FetidToot has quit [Ping timeout: 250 seconds]
FetidToot1 is now known as FetidToot
NightMonkey has quit [Ping timeout: 260 seconds]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
NightMonkey has joined #ruby
some14u has joined #ruby
willfish has quit [Quit: WeeChat 4.0.2]
willfish has joined #ruby
willfish has quit [Ping timeout: 244 seconds]
c10l6 has joined #ruby
c10l6 has quit [Client Quit]
c10l6 has joined #ruby
Guest64 has joined #ruby
duderonomy has quit [Quit: Textual IRC Client: www.textualapp.com]
<Guest64> is the following a bug?
<Guest64> ```
<Guest64> x = {a: 10}
<Guest64> s = x and x[:a]
<Guest64> ```
<Guest64> The output is as I'd expect (`10`), but the assignment results in `s = x`, which I do not expect.
<Guest64> Unless `=` has a higher precedence than `and`, which would be surprising
<llua> what was the expected result?
<Guest64> I would have expected `s` to equal 10
<llua> use &&
<Guest64> ah.. googling the different quickly displays: "WARNING: and even has lower precedence than =" ;)
<Guest64> thanks
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
Guest64 has quit [Quit: Client closed]
Argorok has quit [Quit: Connection closed for inactivity]
duderonomy has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
some14u has joined #ruby