Linux_Kerio has quit [Read error: Connection reset by peer]
pusewicz has joined #ruby
osc4rpt has quit [Ping timeout: 260 seconds]
<pusewicz>
Hey! I wrote a Vim plugin manager in Ruby (as the scope seemed small to try to write a little CLI tool). It's available at https://github.com/pusewicz/vimpk. I'd love to hear thoughts on the README, so that I can make it easier for someone landing on the github repo to understand what this tool is, what it does and how to use it. Thanks!
osc4rpt has joined #ruby
grenierm has quit [Ping timeout: 250 seconds]
osc4rpt has quit [Ping timeout: 268 seconds]
osc4rpt has joined #ruby
jenrzzz has joined #ruby
jenrzzz has quit [Ping timeout: 272 seconds]
<ih8u>
how can i get nil to print as "nil"
jenrzzz has joined #ruby
jenrzzz has quit [Ping timeout: 252 seconds]
<ih8u>
specifically as part of string interpolation
<mange>
"x is #{x.inspect}"?
<ih8u>
i'd like to do it as inspect
<ih8u>
i'm seeing something strange
<ih8u>
in 3.1.2 irb:
<ih8u>
pp "!!!", "#{nil}"
<ih8u>
"!!!"
<ih8u>
"nil"
<ih8u>
but if i put that same line in a file and run with `ruby _.rb`:
<ih8u>
"!!!"
<ih8u>
""
<ih8u>
what's up with that?
<mange>
What does nil.to_s do in your irb?
<ih8u>
can anyone reproduce?
<ih8u>
=> ""
<mange>
I couldn't reproduce with 3.1.4. I'm building 3.1.2 now.
<ih8u>
wait, it's stopped doing it in irb
<ih8u>
weird
<ih8u>
i must have read something wrong or something
<ih8u>
`pp nil` will print "nil" in irb and ruby, and `pp "#{nil}"` will print "" in both
<ih8u>
i did in one file extend class NilClass to try `def to_s "nil" end`
<mange>
Yep, can't reproduce in 3.1.2. I would expect pp "!!!", nil; to print "!!!" then nil, but never "nil". "#{nil}" should always be the same as nil.to_s, but you can redefine that with class NilClass; def to_s = "nil"; end; at which point pp "#{nil}" will print "nil".
<ih8u>
maybe that messed up my irb temporarily while it was present in the file?
<ih8u>
yeah that was my first thought
<ih8u>
unfortunately, it can't be that easy, because apparently the Sequel gem relies on nil returning ""
<ih8u>
i want to be able to print that i've inserted a nil value to a database
<ih8u>
is there a way to scope class extensions?
<mange>
You don't have control of the call site? So you can't just do "inserted: #{x.nil? ? "nil" : x}" or similar?
<mange>
If you wanted to be *absolutely insane* you could redefine to_s to check caller, or something, but that's a shockingly bad idea.
<ih8u>
i don't want to be insane, just lazy
<ih8u>
#{x.nil? ? "nil" : x}" works just fine, but it's too much typing
<ih8u>
and i'd have to go back and change all my existing statements
<ih8u>
instead of just being able to account for nils in some more catch-all way
<ih8u>
something elegant, i guess, lol
<mange>
The catch-all way is to use .inspect, but I guess you don't want to do that for some reason?
<ih8u>
i just already have a bunch of print statements and i don't want to go back manually and add the inspect
Starfoxxes has joined #ruby
<ih8u>
i was hoping pp would be my answer, since it actually prints the characters `nil` if you ask it to
<mange>
So you want to change the behaviour of existing code, but in a way that only affects some call sites? And that seems more elegant to you than using the method that is intended for the thing that you're doing?
<ih8u>
just not with string interpolation
<ih8u>
which i guess makes sense
<ih8u>
i'm just monumentally lazy
<mange>
String interpolation is just to_s, so you can't special-case string interpolation. It just seems like you're "right now" lazy, at the expense of doing more work later when you inevitably have to debug your mess of magic.
user71 has joined #ruby
<ih8u>
yeah, you're probably right
<ih8u>
i thougt it might be a fun learning opportunity
<ih8u>
ruby constantly surprises me with what it allows me to do
<ih8u>
i thought maybe there was some extra magic i wasn't aware of