<rapha>
oh, sorry tsujp ... i completely misread "calling" as "called"
beatif88 has quit [Quit: Best CPUs can count to infinity twice without being bugged out by zero division errors or whatnot.]
_ht has joined #ruby
razetime has joined #ruby
<cxl>
Hi all, why is the MyGem::VERSION string frozen, usually? i.e. why use '1.0.0'.freeze rather than just '1.0.0'?
<leftylink>
I can't say why other gem authors do it, but I would do it for my gems so that someone doesn't accidentally mutate the string, and now nobody knows what the version of my gem is
<rapha>
also in general, whenever you type a string, that's a whole new String object. but when all your strings are frozen, then there'll only be one single String object and it'll get re-used internally.
<rapha>
wait, wasn't it supposed to become the default from 3.0 onwards for strings to be frozen?
___nick___ has joined #ruby
grenierm has quit [Ping timeout: 260 seconds]
razetime has quit [Remote host closed the connection]
nirvdrum has quit [Read error: Connection reset by peer]
nirvdrum_ has joined #ruby
_ht has quit [Remote host closed the connection]
niv has quit [Ping timeout: 265 seconds]
_ht has joined #ruby
mooff has quit [Quit: Ping timeout (120 seconds)]
mooff has joined #ruby
micro has quit [Ping timeout: 260 seconds]
mooff has quit [Ping timeout: 250 seconds]
mooff has joined #ruby
micro has joined #ruby
litera53 has joined #ruby
Milos has quit [Ping timeout: 255 seconds]
antipr4 has joined #ruby
pausel7 has quit [Ping timeout: 256 seconds]
<ox1eef_>
cxl: I would guess it has become common 'frozen_string_literal: true' magic comment is a linter default these days.
litera53 has quit [Ping timeout: 268 seconds]
litera53 has joined #ruby
Milos has joined #ruby
antipr4 has quit [Ping timeout: 265 seconds]
<ox1eef_>
I have settled on Gem.version lately because if Gem is a module that is included then you also end up with the VERSION constant in scope which is weird to me.
<ox1eef_>
rapha: I guess it did not happen:
<ox1eef_>
['foo'.frozen?, RUBY_VERSION]
<ox1eef_>
=> [false, "3.2.1"]
graywolf has joined #ruby
ollysmith has quit [Quit: ZNC 1.8.2+deb3+b4 - https://znc.in]
ollysmith has joined #ruby
NonatoAguiar has joined #ruby
NonatoAguiar39 has joined #ruby
<NonatoAguiar39>
good afternoon people!
<NonatoAguiar39>
please
<NonatoAguiar39>
I have a field (slug) and I would like it to be filled in automatically by joining two other fields at the time of the create method. It would be possible? I've been testing with params but it didn't work.
<NonatoAguiar39>
less elegant (I'm a beginner), but should it work too?
<NonatoAguiar39>
this in the controller
razetime has quit [Remote host closed the connection]
<ox1eef_>
NonatoAguiar39: String does not have a .save method.
<ox1eef_>
Is slug a column or an association ?
<NonatoAguiar39>
column
<ox1eef_>
Then it would be @user.save, and you should check the return value if @user.save to see if it was successful or not.
<ox1eef_>
And, I think it would be better to have User.create_slug that took params[:foo] and params[:bar]. User input usually needs sanitized and validation, so even better would be to assign params[:foo] and params[:bar] to an instance of User, and hook into the lifecycle of ActiveRecord objects (before validation, validation, etc).
<NonatoAguiar39>
not really, sorry I accidentally typed it, it's just @user.save mesemo
<NonatoAguiar39>
not really, sorry I accidentally typed it, it's just @user.save anyway
<ox1eef_>
No worries, but see the last message. User input normally needs sanitized and validated.
<ox1eef_>
A naive, and simple slug implementation might be: [params[:foo], params[:bar]].compact.join("-").gsub(/[^A-Za-z0-9]/, '-')
<ox1eef_>
Best to downcase as well (add .downcase to the end of it).
desnudopenguino1 has joined #ruby
desnudopenguino has quit [Ping timeout: 252 seconds]
desnudopenguino1 is now known as desnudopenguino
<NonatoAguiar39>
I already have the friendly_id gem, but I didn't know that it joined two fields at the time of create. I'll try the options you said. Thank you very much.
uratom77 has joined #ruby
<ox1eef_>
+1
egality has joined #ruby
desnudopenguino1 has joined #ruby
desnudopenguino has quit [Ping timeout: 250 seconds]
desnudopenguino1 is now known as desnudopenguino
NonatoAguiar39 has quit [Quit: Client closed]
<myappie>
if you have foreign letters and stuff you might wanna add: