havenwood changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.1, 3.0.3, 2.7.5: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
ur5us has joined #ruby
Guest3952 has quit [Ping timeout: 250 seconds]
weaksauc_ has joined #ruby
weaksauce has quit [Ping timeout: 256 seconds]
<adam12> mooff: Sometimes I like the module builder pattern. class Foobar < Module.
<adam12> mooff: And sometimes I like to mod = Module.new; const_set(:some_const, mod); mod.define_method.
<mooff> ooh, module builder sounds neat
<adam12> I think there was a Rubyconf or Railsconf talk on it recently.
<mooff> :: class Foobar < Module; def cool() end end; f = Foobar.new
<ruby-eval> => #<Foobar:0x04426a90>
<mooff> :: f.respond_to? :cool
<ruby-eval> => true
<mooff> :: Object.new.extend f
<ruby-eval> => #<Object:0x04435d10>
<mooff> :: _.respond_to? :cool
<ruby-eval> => false
<mooff> that's funky. you'd need some plumbing to define instance methods for the module, wouldn't you?
<adam12> mooff: Yeah. Usually define_method inside initialize();
<adam12> class IsAwesome < Module; def initialize(awesome = true); define_method(:awesome?) { awesome }; end; end; class Widget; include IsAwesome.new(true); end; Widget.new.awesome?
<mooff> include AwesomeStruct.new(:ooh, :cool)
<mooff> :: (0..Float::INFINITY).find { |i| rand(100).zero? }.then { |n| "Took #{n} times to roll a zero" }
<ruby-eval> => "Took 124 times to roll a zero"
<mooff> that one's useful at times. especially if you .lazy.map { turn it into something you want }.find { }
<mooff> now there's (0..) instead of (0..Float::INFINITY) .. ahh
Cena has joined #ruby
Cena has quit [Client Quit]
<ox1eef> i like Module.new {} - great for creating modules on the fly, using const_set on the module is something i don't think i've done before, but interesting as well. 'class Foo < Module' is what crosses the line, too weird.
Cena has joined #ruby
Cena has quit [Client Quit]
Cena has joined #ruby
artemon has joined #ruby
Cena has quit [Client Quit]
TCZ has quit [Quit: Leaving]
Rounin has quit [Ping timeout: 240 seconds]
ikowasz has quit [Ping timeout: 256 seconds]
bluedust has joined #ruby
ur5us has quit [Ping timeout: 240 seconds]
donofrio has quit [Ping timeout: 240 seconds]
<havenwood> mooff: and you can drop the |i|
<havenwood> ox1eef: Both are occationally handy.
<ox1eef> it is certainly clever code. in the past i've used it to group, or include - other modules which were named, then returning the anonymous module from a method. it has a nice style or way to it that would be great to see encouraged in ruby.
bluedust_ has joined #ruby
bluedust has quit [Ping timeout: 256 seconds]
gr33n7007h has quit [Ping timeout: 252 seconds]
oxfuxxx has joined #ruby
teclator has joined #ruby
oxfuxxx has quit [Ping timeout: 256 seconds]
<nakilon> IIRC I used Module.new to split logically some sets of methods I put together into a project autotests library defined in spec_helper.rb
<nakilon> there was no point in declaring a constant that won't even be used
<nakilon> except of the immediate local inclusion
_ht has joined #ruby
Cena has joined #ruby
Cena has quit [Ping timeout: 256 seconds]
Rounin has joined #ruby
<ox1eef> it can make for appealing syntax, eg: include Foo.bar
weaksauc_ has quit [Ping timeout: 272 seconds]
Guest3952 has joined #ruby
weaksauce has joined #ruby
bluedust has joined #ruby
bluedust_ has quit [Ping timeout: 240 seconds]
bluedust has quit [Remote host closed the connection]
TCZ has joined #ruby
taupiqueur has joined #ruby
gr33n7007h has joined #ruby
fercell has joined #ruby
ferr_ has joined #ruby
fercell has quit [Ping timeout: 256 seconds]
bluedust has joined #ruby
roadie has left #ruby [ERC (IRC client for Emacs 25.3.50.1)]
donofrio has joined #ruby
Guest2 has joined #ruby
Guest2 has quit [Client Quit]
Aylat has joined #ruby
Aylat has joined #ruby
Aylat has quit [Changing host]
Aylat_ has joined #ruby
Aylat_ has quit [Changing host]
Aylat_ has joined #ruby
Aylat has quit [Ping timeout: 272 seconds]
ikowasz has joined #ruby
Aylat_ has quit [Read error: Connection reset by peer]
ua_ has quit [Ping timeout: 256 seconds]
bluedust has quit [Remote host closed the connection]
Sheilong has joined #ruby
TCZ has quit [Quit: Leaving]
ua_ has joined #ruby
bluedust has joined #ruby
gr33n7007h has quit [Quit: WeeChat 3.4]
TCZ has joined #ruby
TCZ has quit [Remote host closed the connection]
gr33n7007h has joined #ruby
jhawthorn has quit [Quit: ZNC 1.8.2 - https://znc.in]
jhawthorn has joined #ruby
bit4bit has joined #ruby
bit4bit has quit [Ping timeout: 240 seconds]
gproto23 has joined #ruby
gproto23_ has joined #ruby
taupiqueur has quit [Quit: taupiqueur]
weaksauc_ has joined #ruby
basso7 has joined #ruby
yuckey2d9 has joined #ruby
mbrndtgn4 has joined #ruby
whysthatso12507 has joined #ruby
Artea- has joined #ruby
entropy has joined #ruby
benjaminwil has joined #ruby
ollysmith_ has joined #ruby
Spitfire_ has joined #ruby
seabre_ has joined #ruby
greyrat_ has joined #ruby
pandabot_ has joined #ruby
Guest6 has joined #ruby
teclator_ has joined #ruby
_ht_ has joined #ruby
Guest6 has quit [Client Quit]
finstern1s has joined #ruby
yos has joined #ruby
yos has quit [Changing host]
yos has joined #ruby
weaksauce has quit [*.net *.split]
Rounin has quit [*.net *.split]
_ht has quit [*.net *.split]
teclator has quit [*.net *.split]
Artea has quit [*.net *.split]
greyrat has quit [*.net *.split]
yuckey2d has quit [*.net *.split]
pandabot has quit [*.net *.split]
yossarian has quit [*.net *.split]
splud has quit [*.net *.split]
benjamin- has quit [*.net *.split]
seabre has quit [*.net *.split]
e2 has quit [*.net *.split]
basso has quit [*.net *.split]
entropie has quit [*.net *.split]
mbrndtgn has quit [*.net *.split]
Spitfire has quit [*.net *.split]
ollysmith has quit [*.net *.split]
finsternis has quit [*.net *.split]
whysthatso1250 has quit [*.net *.split]
txdv has quit [*.net *.split]
yuckey2d9 is now known as yuckey2d
entropy is now known as entropie
whysthatso12507 is now known as whysthatso1250
mbrndtgn4 is now known as mbrndtgn
basso7 is now known as basso
splud has joined #ruby
Rounin has joined #ruby
txdv has joined #ruby
e2 has joined #ruby
gproto23 has quit [Remote host closed the connection]
gproto23_ has quit [Remote host closed the connection]
fef has joined #ruby
Pixi_ has joined #ruby
Pixi has quit [Ping timeout: 256 seconds]
<adam12> Morning
<gr33n7007h> morning adam12
Pixi_ has quit [Quit: Leaving]
bluedust has quit [Remote host closed the connection]
<adam12> gr33n7007h: How goes
Pixi has joined #ruby
bluedust has joined #ruby
ikowasz has quit [Ping timeout: 240 seconds]
<gr33n7007h> adam12: not bad mate
<adam12> gr33n7007h: Cool :)
<gr33n7007h> adam12: you good?
fef has quit [Remote host closed the connection]
aeris has quit [Remote host closed the connection]
fef has joined #ruby
aeris has joined #ruby
<adam12> gr33n7007h: Not too bad. Happy Friday!
<gr33n7007h> adam12: good, good. happy friday mate!
ikowasz has joined #ruby
ikowasz has quit [Ping timeout: 245 seconds]
orbyt has joined #ruby
bluedust has quit [Remote host closed the connection]
taupiqueur has joined #ruby
bluedust has joined #ruby
bluedust has quit [Remote host closed the connection]
taupiqueur has quit [Ping timeout: 252 seconds]
mksybr has joined #ruby
<mksybr> is there any way i can make Regexp::new default to multiline mode?
bluedust has joined #ruby
bluedust has quit [Remote host closed the connection]
<mksybr> not really sure what im doing tbh https://www.toptal.com/developers/hastebin/qijinacela.rb
<mooff> fwiw, Regexp#initialize isn't called for regex literals
<mooff> (just tried to monkey patch it)
bluedust has joined #ruby
<mksybr> ahh, i was just about to ask if you knew what literals do
taupiqueur has joined #ruby
bluedust has quit [Remote host closed the connection]
<adam12> mksybr: Just curious why you want to default to multiline mode
<mksybr> prefer typing ^ $ over \A \Z
ur5us has joined #ruby
<adam12> Gotcha.
<mooff> /^foo$/m aint so bad, surely
<mksybr> that is true :)
<adam12> I'd probably prefer the explicit modifier too...
taupiqueur_ has joined #ruby
taupiqueur has quit [Ping timeout: 250 seconds]
orbyt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us has quit [Ping timeout: 250 seconds]
taupiqueur has joined #ruby
taupiqueur_ has quit [Ping timeout: 250 seconds]
orbyt has joined #ruby
teclator_ has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
<havenwood> mksybr: +1 just use Regexp::MULTILINE repeatedly. Make a helper function if you want to DRY it up rather than modifying the core class.
taupiqueur_ has joined #ruby
taupiqueur has quit [Ping timeout: 256 seconds]
ur5us has joined #ruby
ur5us has quit [Remote host closed the connection]
ur5us has joined #ruby
donofrio has quit [Read error: Connection reset by peer]
orbyt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
fef has quit [Ping timeout: 240 seconds]
havenwood has quit [Quit: The Lounge - https://thelounge.chat]
havenwood has joined #ruby
ur5us has quit [Ping timeout: 245 seconds]
perrierjouet has quit [Quit: WeeChat 3.4]
perrierjouet has joined #ruby
<mooff> so i have a method which writes to a socket, and takes a block to call when a reply is received later.. asynchronously
<mooff> how might i turn that into a 'synchronous' enumerator?
<mooff> e.g. take an array, and map each value to a reply, sequentially
<mooff> sorry if i'm not describing it well. i feel like it should be possible with some technique, involving Enumerator and/or Fibers
<mooff> but i can't figure out quite what
wand has joined #ruby
<nakilon> what do you mean "a block to call asynchronously"? isn't socket read blocking in a loop?
<nakilon> or do you mean you read sync but then call the block async? that's probably where you should wait for the block to finish before continuing the read
<weaksauc_> mooff post some code of what you are trying?
<nakilon> in my irc bot tests I don't care about syncing -- I just read the number of replies the test assumes to get and if all the tests pass then it's by 99.999% chance ok, if not then not
<mooff> the ugly but working thing i got yesterday was:
<mooff> %i(do_this then_this finally_that).each { |action| ack = false; request(:task, action) { ack = true }; sleep 0.01 until ack }
<nakilon> if there was not enough or excessive replies the tests would fail because of their assertions anyway
<nakilon> if there are 100 tests the only way to miss the error is if there is an extra reply in the last test that is 1% chance
perrierjouet has quit [Quit: WeeChat 3.4]
<nakilon> (assuming you reuse the connection)
<mooff> to concretize.. i have a couple dozen bots running on different threads. they have a request method which takes an IRC command, gives it a label(*), and stores a block to be called when the server acknowledges that command
<mooff> (*) https://dpaste.org/rUJH (IRCv3 labeled-response)
_ht_ has quit [Remote host closed the connection]
<mooff> i wanted to take a folder of ASCII art... and print each piece of art using a random bot, waiting for one bot's art piece to complete before starting the next
<mooff> i figured there's gotta be a way to use Fibers to do it without resorting to "sleep 0.01 until local_var_has_been_updated"
perrierjouet has joined #ruby
taupiqueur_ has quit [Ping timeout: 256 seconds]
<mooff> trying out this: https://dpaste.org/sdUv
TCZ has joined #ruby
robotmay has quit [Quit: No Ping reply in 180 seconds.]
robotmay has joined #ruby
<ox1eef> another thing you might be able to do is suspend thread(s) with Thread#{resume,stop}.
hack3r_v_ has joined #ruby
<ox1eef> i seem to remember the code youve shared already using shared, globally accessible state - that mixed with threads doesn't sound too good.
<mooff> for what it's worth, that isn't at play :-)
<mooff> the hack i was exploring then doesn't seem practical, so only the bot running in the main thread sets / uses globals
<ox1eef> well, any reason to try fibers is reason enough. i wish i had a use case for them.
TCZ has quit [Quit: Leaving]
<mooff> i struggled to see one before, to be honest
<mooff> "that's just blocks with extra steps"
<sam113101> what's a good book on ruby for those who already know the language but are pretty rusty… I think I started on ruby 1.7 and haven't really kept up because I don't program much
cognemo has quit [Quit: ZNC 1.8.2 - https://znc.in]
cognemo has joined #ruby
taupiqueur has joined #ruby
<apotheon> sam113101: You could give Eloquent Ruby a shot. It's a little old, but I don't think the language has changed enough to make it unuseful.
taupiqueur_ has joined #ruby
taupiqueur has quit [Ping timeout: 272 seconds]
<weaksauc_> another vote for eloquent ruby. excellent book and the language hasn't changed all that much sam113101
taupiqueur_ has quit [Ping timeout: 240 seconds]
taupiqueur has joined #ruby
<apotheon> Eloquent Ruby is pretty much my go-to answer for anything that isn't advanced Ruby.
<apotheon> It's one of the best books for getting started with a programming language that I've ever seen.
<apotheon> possibly the best
taupiqueur has quit [Ping timeout: 240 seconds]
taupiqueur has joined #ruby