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
<mooff> :: IO.readline.upcase
<ruby-eval> ERROR: private method `readline' called for IO:Class
<ruby-eval> Did you mean? readlines
<mooff> :: readline.upcase
<mooff> :: hello Garb0
<ruby-eval> => "HELLO GARB0\n"
<mooff> let's find it from the docs
<mooff> :: maxlen = 1024; respond_to? :read_nonblock
<ruby-eval> => false
<mooff> :: $stdin.read_nonblock(maxlen)
<ruby-eval> ERROR: undefined local variable or method `maxlen' for main:Object
<mooff> ::!
<ruby-eval> [Terminated]
<mooff> :: maxlen = 1024 # local variables should stick now
<ruby-eval> => 1024
<mooff> :: $stdin.read_nonblock(maxlen)
<ruby-eval> ERROR: Bad file descriptor @ rb_io_set_nonblock - <STDIN>
<ruby-eval> <internal:io>:63:in `read_nonblock'
<Garb0> mooff, i don't think readline has nonblocking
<Garb0> i checked the docs over and over
<mooff> Garb0: i've been using this:
<mooff> def lines
<mooff> yield socket.readline until socket.eof?
<mooff> end
<Garb0> Aha! Readline.redisplay does it
<Garb0> mooff, thanks
<Garb0> i swear i was literally 3 seconds away from pulling my hair and rewriting it in Go
<mooff> i understand
<mooff> i've had hair pulling trying to get Ruby io reading not to block
<mooff> some parts of the docs could stand to be improved
<mooff> Garb0: lines() will raise in some conditions
<mooff> abrupt disconnect situations
<Garb0> It doesn't help that there's NO good cmdline lib for ruby.
<Garb0> mooff, lol I'm not even doin sockets at all, it's just cmdline stuff
<mooff> you mean like.. what's that spf13 one for Go
<Garb0> how the hell did metasploit guys make such a good cmdline is beyond me
<mooff> :)
<mooff> i want to make a first class command line shell in Ruby
oxfuxxx has quit [Ping timeout: 240 seconds]
<mooff> a replacement for bash where you use a really slick DSL
Starfoxxes has quit [Ping timeout: 240 seconds]
Starfoxxes has joined #ruby
<mooff> for the ThreadLocalDelegator.. i realised earlier you'd unfortunately need to dup the object if you wanted to store it, reference it after the event has finished
<mooff> maybe that sort of makes it like Rust in a sense. threads have to unbox them specially if they want to use them
<mooff> could use the unary operator for that. class ThreadLocalDelegator; def ~@()= __getobj__.dup end
<mooff> or actually.. class ThreadLocalDelegator; def ~@()= __getobj__ end
taupiqueur has quit [Ping timeout: 256 seconds]
bluedust has joined #ruby
bluedust has quit [Ping timeout: 240 seconds]
<Garb0> mooff, i have given up, time for extreme measures: ruby ncurses
TomyWork has quit [Remote host closed the connection]
markong has quit [Ping timeout: 256 seconds]
TCZ has joined #ruby
peer has quit [Quit: whoops]
peer has joined #ruby
hanzo has joined #ruby
Rounin has quit [Ping timeout: 240 seconds]
goepsilongo has joined #ruby
justAstache has quit [Read error: Connection reset by peer]
justAstache has joined #ruby
TCZ has quit [Quit: Leaving]
PedroG1 has joined #ruby
Guest6792 has quit [Ping timeout: 240 seconds]
perrierjouet has quit [Quit: WeeChat 3.4]
Garb0 has quit [Read error: Connection reset by peer]
bluedust has joined #ruby
<PedroG1> new_hash = ['a', 'b', 'c'].map{ |x| => some_function(x) }
<PedroG1> Somehow this is failing, whats the best way to create a hash whose value is that some_function
<havenwood> PedroG1: %w[a b c].to_h { |char| [char, some_function(char)] }
<PedroG1> Havenwood, thank you for ur help
fdan has joined #ruby
Hazey_Dream has quit [Ping timeout: 256 seconds]
fdan has quit [Quit: Client closed]
dannyAAM has quit [Ping timeout: 240 seconds]
dannyAAM has joined #ruby
_ht has joined #ruby
ZAJDAN has quit [Read error: Connection reset by peer]
teclator has joined #ruby
Guest6792 has joined #ruby
hanzo has quit [Quit: Connection closed for inactivity]
_ht has quit [Remote host closed the connection]
Rounin has joined #ruby
yuckey2d has quit [Ping timeout: 240 seconds]
yuckey2d has joined #ruby
TomyWork has joined #ruby
hololeap_ has quit [Ping timeout: 240 seconds]
ZAJDAN has joined #ruby
<ZAJDAN> I have a class where I define method(which use library Net/Http). I would like to call this class method from controller and pass parameters for HTTP request(login). Should I define the method in the class as 'self' or as instance method?
infinityfye has joined #ruby
fdan has joined #ruby
roadie has quit [Ping timeout: 256 seconds]
fdan has quit [Client Quit]
fdan has joined #ruby
roadie has joined #ruby
markong has joined #ruby
oxfuxxx has joined #ruby
fdan has quit [Quit: Client closed]
Aylat has joined #ruby
oxfuxxx has quit [Ping timeout: 256 seconds]
roadie has quit [Read error: No route to host]
roadie has joined #ruby
roadie has quit [Ping timeout: 268 seconds]
roadie has joined #ruby
taupiqueur has joined #ruby
ZAJDAN has quit [Read error: Connection reset by peer]
ZAJDAN has joined #ruby
roadie has quit [Ping timeout: 252 seconds]
roadie has joined #ruby
roadie has quit [Read error: Connection reset by peer]
roadie` has joined #ruby
moons has joined #ruby
moons has quit [Client Quit]
TCZ has joined #ruby
fdan has joined #ruby
Tempesta has quit [Quit: See ya!]
TCZ has quit [Quit: Leaving]
Tempesta has joined #ruby
oxfuxxx has joined #ruby
gproto23 has joined #ruby
gproto23 has quit [Remote host closed the connection]
gproto23 has joined #ruby
<adam12> ZAJDAN: As with everything, it depends. If it has no state, you could keep it a class method for simplicity sake.
Aylat has quit [Read error: Connection reset by peer]
<ZAJDAN> adam12: in my case I do not need keep a state(offline, online)..just do login, get sessionID and nothing more
oxfuxxx has quit [Remote host closed the connection]
taupiqueur has quit [Quit: taupiqueur]
<ox1eef> ZAJDAN: make sure to handle failure gracefully - generally i think long blocking operations are best done asynchronous to the user but of course every case is different.
<ZAJDAN> ox1eef: Thank YOu for any hint and recommendation
<ox1eef> by rescuing SystemCallError you should catch the various Errno errors that may arise at a socket level.
<ZAJDAN> ox1eef: This I do I have a case block to catch (Net::HTTPSuccess, Net::HTTPBadRequest, Net::HTTPUnauthorized, etc) and accordingly to the result I show message
taupiqueur has joined #ruby
xuochi has joined #ruby
<ox1eef> those are not exceptions but classes representing a response.
<ox1eef> you should handle what happens when you don't get a response as well, due to some network error
TCZ has joined #ruby
<nakilon> (the exception you might are some of these: https://dpaste.org/psN9/raw)
<nakilon> *you might have
<ox1eef> No need to list all the errno's individually like that, SystemCallError is their superclass.
bluedust_ has joined #ruby
<ZAJDAN> ox1eef: "Net::OpenTimeout"
<nakilon> ox1eef I like explicity
bluedust has quit [Ping timeout: 240 seconds]
<mooff> what about just not rescuing them
<mooff> btw, i didn't know to_h took a block :-)
bluedust has joined #ruby
bluedust_ has quit [Ping timeout: 256 seconds]
<adam12> mooff: It's recent... I think?
<adam12> Ruby 2.6.
<ox1eef> nakilon: it is hard work to track all of them one by one, i'd say even prone to error - you could easily overlook one of them.
xuochi has quit [Quit: leaving]
<ox1eef> ZAJDAN: indeed, that's one to rescue as well.
yxhuvud has quit [Remote host closed the connection]
<nakilon> I prefer to know what exactly was eaten by my "rescue"s
<ox1eef> fair enough
<ox1eef> i'd approach this problem with a module implementing === - where you can handle all these different cases, but rescue one exception or well, module.
bluedust has quit [Remote host closed the connection]
<mooff> after installing a gem, how can i ask RubyGems to update $LOAD_PATH in a session without restarting it?
<adam12> mooff: "gem 'somegem'"?
<adam12> Not sure what you mean by session tho?
<ox1eef> looking at the Gem module, "Gem.add_to_load_path()" seems rather direct.
<mooff> adam12: s/session/process/ or s/session/running Ruby VM/ :)
<ox1eef> hot reloading in the other words.
<mooff> thanks ox1eef. hopefully that does it
<ox1eef> another place to look, pry and its install-gem command. i believe it allows the same thing: install and require into active process.
<mooff> add_to_load_path didn't find the new gem
TCZ has quit [Quit: Leaving]
<ox1eef> sorry, got to jump off for a meeting - id suggest looking at the rest of the Gem methods, probably need to refresh the cache. the pry command solves it as well.
yxhuvud has joined #ruby
<ox1eef> meeting cancelled
<ox1eef> pry uses Gem.install + then follows with a require
<mooff> np
<mooff> thanks for the pointers. just found Gem.refresh, which does it
<mooff> "Refresh available gems from disk"
<ox1eef> cool
<mooff> how does the Ruby community feel about improving its posture w.r.t package update attacks?
<ox1eef> what are package update attacks
<mooff> supply chain attacks. i didn't feel i could use both 'posture' and 'supply chain attacks' in one sentence without rolling eyes at myself
<mooff> but it does seem that the Ruby ecosystem is still unguarded where it comes to the ability for someone to push a malicious update
<ox1eef> generally i think we're behind others, with npm putting publishing behind 2FA and i can think of many instances where packaging falls behind. another one i found recently was that bundler will overwrite the binaries of other gems, so you could maliciously replace another bin the user trusts.
<ox1eef> yes, id agree with that
<mooff> imo, 2FA is important but not enough
<ox1eef> but we do not even have that, so i think that gives an idea
<mooff> i was reading that PHP are going in what seems like the (only) sensible option - peer attestation published to transparency logs
<ox1eef> it would probably be a huge, diffilcult effort to try 2FA at publishing time.
<ox1eef> npm is worth watching too, they suffered a lot with these issues
<mooff> i feel like it should be impossible for a new gem, or an update to a gem, to be generally available before the source diff has been peer reviewed
<ox1eef> sounds awful tbh, imagine those just publishing quick gems and the like.
<mooff> without literal eyes on the code before it runs on thousands of developer machines (with full r/w to their home directories, private keys, source code, databases, etc)
<ox1eef> i was totally wrong, there is 2FA support across the spectrum: https://guides.rubygems.org/setting-up-multifactor-authentication/
<mooff> cool
<ox1eef> i just enabled it, seems to work very nicely
<mooff> i feel like the risks are still high, even with 2FA
<mooff> to be honest, i'm surprised there haven't been more attacks so far
<ox1eef> thanks be to God.
<nakilon> any link to any article telling how Ruby is used besides of websites? to send it to stupid HRs
<nakilon> I mean recruiters
bluedust has joined #ruby
<ox1eef> probably needs to be written
perrierjouet has joined #ruby
_ht has joined #ruby
<nakilon> I just have to explain every single day what is the programming
ZAJDAN has quit [Read error: Connection reset by peer]
<ox1eef> blog about it then link them to it :) youre probably well informed by now.
<ox1eef> i'd have to think about it and research it
<ox1eef> DragonRuby comes to mind as an obvious one.
<ox1eef> i seem to remember an automation tool by the name of puppet - not sure it even still exists, but id assume devops is another place ruby shines.
<ox1eef> Go more so though.
<nakilon> good idea, if only I had a blog
<ox1eef> lucky for you another ruby area is great is for building static websites :)
<nakilon> for now I just copypaste the list of my repos, but that's not educational, they only come to a conclusion "what a weirdo, delete"
<nakilon> _--
<ox1eef> of course, it has to be packaged in an appropiate way
<ox1eef> a gist as markdown would be the least effort and then at least they might understand it
taupiqueur has quit [Ping timeout: 240 seconds]
fdan has quit [Quit: Client closed]
markong has quit [Ping timeout: 240 seconds]
taupiqueur has joined #ruby
roadie` has quit [Quit: ERC (IRC client for Emacs 25.3.50.1)]
infinityfye has quit [Quit: Leaving]
mbarbar has quit [Quit: ZNC 1.7.2+deb3 - https://znc.in]
mbarbar has joined #ruby
gproto23 has quit [Remote host closed the connection]
bluedust_ has joined #ruby
bluedust has quit [Ping timeout: 272 seconds]
HyLian_ has quit [Ping timeout: 256 seconds]
HyLian has joined #ruby
bluedust_ has quit [Ping timeout: 256 seconds]
oxfuxxx has joined #ruby
dviola has quit [Ping timeout: 256 seconds]
some14u has joined #ruby
some14u has quit [Client Quit]
some14u has joined #ruby
teclator has quit [Remote host closed the connection]
some14u is now known as goesting
TomyWork has quit [Quit: Leaving]
_ht has quit [Remote host closed the connection]
goesting has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<nakilon> TIL __dir__ is affected by Dir.chdir (
<leah2> ?
teclator has joined #ruby
TCZ has joined #ruby
TCZ has quit [Quit: Leaving]
markong has joined #ruby
robotmay has quit [Quit: No Ping reply in 180 seconds.]
oxfuxxx has quit [Ping timeout: 256 seconds]
robotmay has joined #ruby
<mooff> what *is* __dir__?
<mooff> :: ObjectSpace.each_object().count
<ruby-eval> => 10406
<mooff> :: ObjectSpace.each_object.select {|o| o.send :__dir__}
<ruby-eval> => [#<Ractor:#1 running>]
graywolf has joined #ruby
graywolf has quit [Client Quit]
graywolf has joined #ruby
graywolf has quit [Client Quit]
<mooff> i spotted __dir__ in #methods the other day and got that from ruby-eval ^
Guest6792 has quit [Ping timeout: 256 seconds]
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
dviola has joined #ruby
oxfuxxx has joined #ruby
<mooff> it confused me, but Ractor always replies to send. __dir__ is simply nil