<vvn>
hash['foo'] = Base64.decode64(hash['foo']) if hash.has_key? 'foo'
graaff has joined #ruby
ox has joined #ruby
oz has quit [Ping timeout: 255 seconds]
cappy has quit [Quit: Leaving]
<adam12>
vvn: Is there more to this? Maybe we can offer a better solution knowing more of the problem (ie. transform_values)
<vvn>
no that's it, an optional key which value is base64 encoded (and I want to decode it if it is present)
<adam12>
You want to decode if if it's present and then re-assign it to the same value? So it's no longer encoded?
<adam12>
Sounds like transform values to me? hash.transform_values { Base64.decode64(_1) }
<vvn>
can it be conditional? There's only one value which is encoded
<vvn>
oh I don't know the _1 notation
__DuBPiRaTe__ has joined #ruby
Sampersand has joined #ruby
hwpplayer1 has joined #ruby
konsolebox has joined #ruby
Sampersand has quit [Ping timeout: 256 seconds]
eddof13 has quit [Quit: eddof13]
hwpplayer1 has quit [Quit: I'll be back later]
__DuBPiRaTe__ has quit [Quit: Leaving]
hwpplayer1 has joined #ruby
hightower3 has joined #ruby
hightower2 has quit [Ping timeout: 255 seconds]
<lunarkitty>
If you want to avoid variables you can do something like hash['foo'] and hash['foo'] = Base64.decode64(hash['foo'])
<lunarkitty>
(note I'm a fan of `and` over `&&` for *control flow*, some people don't like that, but that's what it's apparently for)
fercell has joined #ruby
<lunarkitty>
if you wanna get really fancy you could use refinements and add a new hash method to do that. But that's way overkill for a single field
cappy has joined #ruby
Sampersand has joined #ruby
hwpplayer1 has quit [Quit: I'll be back later]
<vvn>
I agree for the 'and'
<vvn>
and/or are a bit confused, surprised they didn't get deprecated over time
<o0x1eef>
I often think one-liners like that are best solved with a bit more context about the code - there might be another way to express it
<Sampersand>
i love and/or
brokkoli_origin has quit [Ping timeout: 252 seconds]
brokkoli_origin has joined #ruby
<Sampersand>
Your `hash['foo'] = Base64.decode64(hash['foo']) if hash.has_key? 'foo` is the best way to do it imo vvn
<lunarkitty>
Yeah
<lunarkitty>
The only reason to do it differently is imo if you needed to to a lot of keys
<lunarkitty>
to do*
<o0x1eef>
This could also work: h["foo"] = h["foo"]&.unpack1("m")
<lunarkitty>
that's pretty fancy
<lunarkitty>
sometimes I just monkey patch in a String#from_b64 and #to_b64 :p
<o0x1eef>
Sounds nice
<lunarkitty>
really overkill way if you wanted to do this over and over again without writing the same thing, obviously impractical for this but it was fun lol https://www.jdoodle.com/ia/1sYO
<lunarkitty>
also found a cool replit alternative, apparently they're not free anymore hmm
hwpplayer1 has joined #ruby
lunarkitty has quit [Remote host closed the connection]
<Sampersand>
o0x1eef woudlnt that set `h["foo"]` if it was unset
c10l has quit [Ping timeout: 244 seconds]
<o0x1eef>
Yep - it would assign nil and a key. But IME that rarely matters.
c10l has joined #ruby
lunarkitty has joined #ruby
ih8u2 has joined #ruby
ih8u has quit [Ping timeout: 248 seconds]
ih8u2 is now known as ih8u
Sampersand has quit [Quit: Client closed]
ih8u2 has joined #ruby
ih8u has quit [Ping timeout: 252 seconds]
ih8u2 is now known as ih8u
mange has joined #ruby
mange has quit [Client Quit]
Munto has quit [Quit: Leaving]
hwpplayer1 has quit [Quit: I'll be back]
dhruvasagar has joined #ruby
dhruvasagar has quit [Remote host closed the connection]
TomyWork has quit [Remote host closed the connection]
carpincho has joined #ruby
ftajhii has quit [Read error: Connection reset by peer]
ftajhii has joined #ruby
carpincho has quit [Changing host]
carpincho has joined #ruby
tuxcrafter has quit [Quit: Client closed]
tuxcrafter has joined #ruby
gr33n7007h has quit [Quit: WeeChat 4.4.3]
gr33n7007h has joined #ruby
ox is now known as oz
Sampersand has joined #ruby
<brokkoli_origin>
I don't understand. After i install iruby with 'gem install iruby' it was ok. But 'iruby register --force' doesn't work (not found). But iruby is in gem list. 'gem which iruby' -> ~/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/iruby-0.8.0/lib/iruby.rb . 'gem install iruby' is a bad method or what is the situation? any idea?