<sam113101>
wasn't there a way to address arguments of a block by number? like { $0 > $1 } instead of { |a, b| a > b }, but obviously it's not that
jpn has joined #ruby
nirvdrum has joined #ruby
ixti has joined #ruby
<adam12>
sam113101: _1, _2, etc.
jpn has quit [Ping timeout: 250 seconds]
<sam113101>
adam12: oh, I had tried that but I thought it would start with _0…
Al2O3 has quit [Ping timeout: 250 seconds]
white_magic has quit [Quit: Client closed]
eddof13 has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
nirvdrum has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<leftylink>
I could see beginless ranges being used in a `case` as well. Comparable#clamp could be a possibility too, though there are enough alternatives to that I suppose we can't use that to argue for it
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jdmark has joined #ruby
eddof13 has joined #ruby
<littlebuddy>
Hi! Anybody here happen to be up for hire for a couple of hours to help fix some bugs in Rails?
eddof13 has quit [Client Quit]
jpn has joined #ruby
jpn has quit [Ping timeout: 252 seconds]
<AstrallyForged>
I'm embedding a little Ruby in the larger project. It spawns a Ruby interpreter with a small script and uses stdio for communicating with it. I'm using YAML as a common format.
<AstrallyForged>
It's mostly working, except that it seems to wait for stdin to be closed before doing anything—I need it to process YAML documents one at a time as soon as a complete document is received.
<AstrallyForged>
It's based around `YAML.load_stream $stdin do`.
<AstrallyForged>
Minimal reproduction is to just run `ruby -r yaml -e 'YAML.load_stream($stdin) { |x| pp x }'` in a terminal and type in a few short documents.
Goodbye_Vincent has joined #ruby
gr33n7007h has quit [Ping timeout: 264 seconds]
gr33n7007h has joined #ruby
<leftylink>
well the difficulty I woul dhave with this is, how can it be possible to know when a document ends? for example, with the document "a: b" how do I know I've seen all the key value pairs? there could be another line "c: d" right after, so I can't know
<AstrallyForged>
That's what `...` is for, isn't it?
ur5us has joined #ruby
<leftylink>
I must look very foolish. what I said doesn't make sense anyway because even if ... didn't exist, --- would start a new document anyway and the stream reader could know to start a new document right then and there
<leftylink>
and deal with the prevoius document which was already known to be complete
<leftylink>
in that case all I can say is "what a shame that YAML.load_stream evidently does not do that"
<AstrallyForged>
…it looks like it does what I want if I use EOF instead of `...`.
<AstrallyForged>
But I don't think I can generate EOF when stdin is a pipe to another process…
<AstrallyForged>
Without, y'know, closing it
<AstrallyForged>
…okay, so I guess the solution here is to read more manually from stdin, looking for the marker, and then pass a string to `YAML.load`
Sankalp has quit [Ping timeout: 252 seconds]
<AstrallyForged>
`$stdin.readline "...\n"` ^.^
<AstrallyForged>
(technically this isn't correct YAML; any whitespace can follow the marker…but I'm judging it fine; this is pretty tightly coupled and doesn't need to interoperate)
<gr33n7007h>
AstrallyForged: can you gist your code?
ur5us has quit [Ping timeout: 264 seconds]
Sankalp has joined #ruby
<AstrallyForged>
gr33n7007h: I got it working, thanks!
TomyWork has quit [Remote host closed the connection]
pgib has joined #ruby
Mikaela has quit [Remote host closed the connection]
ahayworth has quit [Ping timeout: 268 seconds]
ahayworth has joined #ruby
cocalero_ has joined #ruby
Aminda has joined #ruby
Aminda has quit [Remote host closed the connection]
Aminda has joined #ruby
Al2O3 has joined #ruby
cocalero_ has quit [Quit: Going offline, see ya! (www.adiirc.com)]
libsys has joined #ruby
jpn has joined #ruby
<libsys>
hello people... I'm working on some minetest based tests, and I need to test a simplified mailer that takes 3 params: `SMTP.sendmail(to, subject, body)` ... internally it uses Net::SMTP, so I need to stub .start and .send_message in order to be able to excecute the test while not actually sending any mail
<libsys>
but IDK how to express that
nmollerup has quit [Remote host closed the connection]
nmollerup has joined #ruby
mikecmpbll has quit [Ping timeout: 252 seconds]
mikecmpbll has joined #ruby
<libsys>
since start opens a block I thought on something like `Net::SMTP.stub(:start, ->(helo, user, secret, authtype) { yield } do |smtp| smtp.stub(:send_message, true) do MySMTP.sendmail('to', 'subject', 'body') end end end`
jpn has quit [Ping timeout: 265 seconds]
<libsys>
but that yield doesn't work and tbh I'm not even sure or what I'm doing
<leftylink>
well, your implementation of start must present the same interface as Net::SMTP.start, otherwise the test will lie about what is and isn't correct. well, the interface of start is that it calls the block, passing the smtp object as block argument. okay, so that means in the worst case, even if minitest supports nothing else, you could say `smtp = Object.new; def smtp.send_message(...) :message_send end`
<leftylink>
and then the implementation of start would just be `yield(smtp)`. of course this has the usual caveats of it doesn't check that the test implementation of send_message has the same args as the original
jpn has quit [Ping timeout: 268 seconds]
reset has quit [Quit: reset]
skuntee4 has quit [Ping timeout: 252 seconds]
Al2O3 has quit [Remote host closed the connection]