<AndreYuhai>
but then I get #<Badge:0x0000560046cbfd80 not initialized>
jottr_ has joined #ruby
<phaul>
initialize is not supposed to return anything. It's supposed to initialize the instance state.
<phaul>
think of like this class X; def self.new(*params); instance = alloc; instance.initialize(*params); instance; end; end
<phaul>
*think of it
<AndreYuhai>
phaul, oh so I should override the new method of the class instead? :)
<phaul>
you can. I'm not sure about should :D
<phaul>
I feel like you are trying to do something that goes against how active record was supposed to be used. Does this logic really have to be in .new?
<AndreYuhai>
phaul, Because I am using accepts_nested_attributes_for. So this is a nested class. If I don't do anything then when I try to save the record, I get an error saying duplicate entry.
<AndreYuhai>
I thought I should override initialize or new as you said. I don't know what other method I should override to do that duplicate check or where.
<AndreYuhai>
phaul, I am already using autosave: true, but maybe I can override before_save and do the duplicate check in there?
jenrzzz has quit [Ping timeout: 264 seconds]
jenrzzz has joined #ruby
<phaul>
I'm pretty much out of my depth, hopefully someone else can answer
RiPuk has quit [Ping timeout: 260 seconds]
RiPuk has joined #ruby
<AndreYuhai>
phaul, I've overridden the class' `new()` method and it works just fine. Thank you. :) Why would it be against how the active record was supposed to be used though? Out of curiosity.
RiPuk has quit [Ping timeout: 260 seconds]
RiPuk has joined #ruby
akem has joined #ruby
doomlist3 has joined #ruby
ur5us has quit [Ping timeout: 260 seconds]
Sina has quit [Quit: Connection closed for inactivity]
<phaul>
My general understanding is that new would create an AR model object (in memory) that can later be saved (to DB) and also it can be checked for validity. Fetching an existing object from DB on calling new surprises me but, I could be wrong
RiPuk has quit [Read error: Connection reset by peer]
RiPuk has joined #ruby
drincruz has joined #ruby
jottr_ has quit [Ping timeout: 256 seconds]
<doomlist3>
i wrote a file.rb but intend irb to as if I ran that code in irb, so those funtions can be used, which flag to use for that
<doomlist3>
irb -r oo.rb
<doomlist3>
/usr/lib/ruby/2.5.0/irb/init.rb:280: warning: LoadError: cannot load such file -- oo.rb
akem has quit [Quit: Leaving]
conta has quit [Quit: conta]
<doomlist3>
phaul: hi
<AndreYuhai>
phaul, so I changed it to create a new one if there isn't a record already in the DB. At least that's my workaround for the duplicate entry error. Hope someone answers if what I am doing is "not to be done" :D
<doomlist3>
def f(x=2) the docs says functions are methods, but i want to call them just like methods so f(arg1,arg2) not this syntax
<AndreYuhai>
doomlist3, irb -r ./oo.rb should work
<doomlist3>
yes
<doomlist3>
AndreYuhai: can i also see the source code loaded without opening the file
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<doomlist3>
and to load that file from within irb require ./oo.rb ?
drincruz has quit [Ping timeout: 260 seconds]
<doomlist3>
i discovered puts `cat oo.rb` to see the whole codebase
<AndreYuhai>
doomlist3, to load that file from within irb require_relative 'oo'
<AndreYuhai>
doomlist3, Not sure about how to see the whole source code loaded but you can use vim within irb so you can edit that file later on
<doomlist3>
i discovered require "~/bin/rb/oo.rb" without seeing the docs!
<doomlist3>
i hate learning by error and trial
<AndreYuhai>
doomlist3, https://github.com/jberkel/interactive_editor this is how you can use vim from within irb. Someone else here had suggested me that here and it's really useful.
<doomlist3>
AndreYuhai: vim within irb?
<AndreYuhai>
doomlist3, Yes, just send the link.
<AndreYuhai>
sent*
<doomlist3>
which cmd are you referring
<doomlist3>
ok the link sorry
ryanar has joined #ruby
jetchisel has quit [Quit: Unfortunately time is always against us -- [Morpheus]]
bodqhrohro has left #ruby ["Leaving"]
woodruffw has quit [Ping timeout: 256 seconds]
jottr_ has joined #ruby
doomlist3 has quit [Ping timeout: 264 seconds]
woodruffw has joined #ruby
woodruffw has quit [Ping timeout: 265 seconds]
chris__ has joined #ruby
chris__ has quit [Ping timeout: 264 seconds]
<AndreYuhai>
when using accepts_nested_attributes_for, passing a hash with nil value for the nested class' attributes still creates the entity with null values. How not to create it when the passed hash has nil value? Because if the key is nil then I get an error undefined method `with_indifferent_access' for nil:NilClass
<AndreYuhai>
Sorry, passing an empty hash would be the first part*
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
codefriar has quit [Ping timeout: 258 seconds]
leitz has joined #ruby
codefriar has joined #ruby
akem has joined #ruby
<leitz>
Ruby.
<leitz>
Ah...I needed a moment of peace and sanity.
* leitz
now heads back to the asylum.
drincruz has joined #ruby
Garb0 has joined #ruby
plutes has quit [Ping timeout: 272 seconds]
codefriar has quit [Ping timeout: 240 seconds]
codefriar has joined #ruby
conta has joined #ruby
codefriar has quit [Ping timeout: 260 seconds]
plutes has joined #ruby
drincruz has quit [Read error: Connection reset by peer]
drincruz has joined #ruby
codefriar has joined #ruby
ellcs1 has quit [Ping timeout: 256 seconds]
<lmat>
I'm getting the error "undefined method `env' for Rails:Module"
<lmat>
This is in an integration test. I have require 'rails/test_help.rb' in my test_helper.
<lmat>
I see in rails/test_help.rb the line "abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?" and it's this Rails.env at the end that's failing.
<lmat>
How can that even fail?
<lmat>
I look online and the only thing I see about this is "That's new in rails 3, and won't be in rails 2.3.3" or so. I'm using rails 5.x...
chalkmonster has joined #ruby
<lmat>
I would like to debug the matter, but I have no idea who should be setting Rails.env or where or how... it's a black box to me.
<lmat>
By the way, I have set RAILS_ENV=test
<lmat>
I see /config/environments/test.rb with Rails.application_configure do at the top and lots of configuration...
<dualfade>
fyi: chalkmonster. love the handle. Thats great !
codefriar has quit [Remote host closed the connection]
<chalkmonster>
dualfade: thanks, do we know each other from before?
codefriar has joined #ruby
<lmat>
I found a clue! I put a typo in config/environments/test.rb and no error about that typo :-o
nicholaslyang has joined #ruby
<lmat>
Well...hmm. I'm wrecking my config files and they're not having any effect.
nicholaslyang has quit [Client Quit]
<lmat>
Of course, I don't know what would/should be calling those config files...it's all a black box :(
chris___ has joined #ruby
<lmat>
yay, I got configuration to break \o/ boot.rb is apparently being read.
conta has quit [Quit: conta]
jottr has joined #ruby
chris___ has quit [Ping timeout: 260 seconds]
<lmat>
So only boot.rb is executed before unit tests in /config?
jottr_ has quit [Ping timeout: 246 seconds]
doomlist3 has joined #ruby
codefriar has quit [Remote host closed the connection]
codefriar has joined #ruby
burningserenity has joined #ruby
codefriar has quit [Remote host closed the connection]
codefriar has joined #ruby
Axy has joined #ruby
dionysus69 has quit [Ping timeout: 246 seconds]
<doomlist3>
for array a[2:3:step] step does not exist in ruby ?
<doomlist3>
this is a problem
siyanda has joined #ruby
Mia has quit [Ping timeout: 240 seconds]
birkbeggar has joined #ruby
siyanda has quit [Remote host closed the connection]
Vagabond[m] has joined #ruby
birkbeggar has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<havenwood>
doomlist3: What's the result you'd like. There's plenty of step in Ruby.
<doomlist3>
x=x+step
<havenwood>
doomlist3: There are multiple ways.
<doomlist3>
list.step accepts only index,length not step
<doomlist3>
memory is poor, havenwood forget python i learnt ruby in 2 days, show me ruby not python
<havenwood>
doomlist3: I just meant show the data you have and the data you want. Like the old UNIX law, data is easier to understand than logic. Like "I have `[*1..5]` and I want `[2, 5]`, as in every third slice.
<havenwood>
doomlist3: al2o3-cr gave the desired return value this time. :)
chris___ has joined #ruby
<doomlist3>
enumerator of ruby seems different than python's
<havenwood>
doomlist3: There's not a Ruby method exactly for this. Several folk have proposed one over the years, and the reply has been to show the usecase.
<havenwood>
doomlist3: Yes, Ruby has an interesting Enumerable with Enumerator setup.
<havenwood>
doomlist3: Enumerable is a module that is mixed into many collections to make them iterable.
<havenwood>
doomlist3: The Enumerable methods are great to learn, since they tend to be available for all sorts of collections.
<phaul>
doomlist3: why do you think that ruby should be approached from a python perspective? There are many things different in ruby enumerator is just one of them. But why wouldn't it be different, if everything were the same they would be the same language
<doomlist3>
phaul: ok
Garb0 has quit [Ping timeout: 260 seconds]
jottr_ has joined #ruby
Garb0 has joined #ruby
TCZ has joined #ruby
jottr has quit [Ping timeout: 246 seconds]
Garb0_ has joined #ruby
baojg has joined #ruby
baojg has quit [Remote host closed the connection]
baojg has joined #ruby
Garb0 has quit [Ping timeout: 265 seconds]
baojg has quit [Remote host closed the connection]
<havenwood>
doomlist3: So depending on what you need, you can #to_i, #Integer, or #Integer with `exception: false`. That's the same for #to_s/#String, #to_f/#Float, etc.
<havenwood>
doomlist3: Does that make sense?
<doomlist3>
yes
ldepandis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
codefriar has quit [Remote host closed the connection]
codefriar has joined #ruby
Garb0 has joined #ruby
Garb0 has quit [Max SendQ exceeded]
Garb0 has joined #ruby
chris___ has quit [Ping timeout: 256 seconds]
Garb0_ has quit [Quit: I'm out.]
nicholaslyang has joined #ruby
gix has joined #ruby
nicholaslyang has quit [Client Quit]
orbyt_ has joined #ruby
Eiam has joined #ruby
cd has joined #ruby
birkbeggar has joined #ruby
birkbeggar has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
doomlist3 has quit [Ping timeout: 256 seconds]
<AndreYuhai>
What's the parameter type for "exists?" method in ActiveRecord::Querying? And is it a good idea to override it? :D
<havenwood>
AndreYuhai: You can ask any method what its parameters are. If you have a good reason to override it, it's a good idea.
<AndreYuhai>
havenwood, Because if I override it then I have to write the block again and I didn't know which parameters it takes. I checked but ActiveRecord::Querying but didn't understand much about how it's defined.
doomlist3 has joined #ruby
<havenwood>
AndreYuhai: Why do you want to override it?
ChmEarl has joined #ruby
<AndreYuhai>
havenwood, Because my class has nested classes and I want to check whether the record exists by joining the nested class.
<AndreYuhai>
havenwood, like User.joins(:user_identifier).find_by(name: 'foo')
<havenwood>
AndreYuhai: Can you just make a scope or something like that instead? On the face of it it doesn't seem like a good idea to override #exists? for this.
* havenwood
tries to quaff some cold coffee
<AndreYuhai>
havenwood, What do you mean make a scope?
birkbeggar has joined #ruby
<havenwood>
AndreYuhai: Just define a new method on the model.
<havenwood>
AndreYuhai: Like a scope does for a collection, but this is for a single record so not technically a scope.
<havenwood>
AndreYuhai: #user_name_exists?
<AndreYuhai>
havenwood, Oh yea so like User.user_name_exists? so I could do the join in that method
Kilo`byte has quit [Quit: ZNC - 1.6.0 - http://znc.in]
<havenwood>
AndreYuhai: Yeah, I think that's going to convolute less than changing a core method.
<havenwood>
AndreYuhai: And it's fine practice.
<AndreYuhai>
havenwood, that sounds better. Thank you for the suggestion :)
sauvin has quit [Read error: Connection reset by peer]
siery has quit [Ping timeout: 256 seconds]
snuz has joined #ruby
troulouliou_div2 has joined #ruby
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
stryek has joined #ruby
BSaboia has joined #ruby
bsdband68 has joined #ruby
alexherbo2 has joined #ruby
nicholaslyang has joined #ruby
bsdbandit-01 has quit [Ping timeout: 256 seconds]
Deesl has joined #ruby
teyas has joined #ruby
greengriminal has joined #ruby
Garb0_ has joined #ruby
Garb0 has quit [Ping timeout: 246 seconds]
roadie has joined #ruby
Garb0_ has quit [Remote host closed the connection]
<teyas>
Hi Folks, I created private Inner classes using "private_constant" so that the inner class cannot be instantiated from anywhere outside. but, if I return the reference to the inner class object, I can call all the methods on that instance anywhere outside. Eventhough I return the reference, I dont want methods to be called outside. So to prevent that, I placed "private_class_method", now I am getting the "undefined_method" error. I have provided the code here
<al2o3-cr>
xco: if you click on the little link "What's this?" it explain ;)
<xco>
al2o3-cr wow. for years i never saw the "what's this?" !!!
<al2o3-cr>
haha np it's easily missed :P
jenrzzz_ has joined #ruby
jenrzzz has quit [Ping timeout: 240 seconds]
dmitriy has joined #ruby
dmitriy has quit [Client Quit]
burningserenity has quit [Ping timeout: 256 seconds]
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jenrzzz_ has quit [Ping timeout: 256 seconds]
roadie has quit [Ping timeout: 256 seconds]
jenrzzz has joined #ruby
ur5us has joined #ruby
roadie has joined #ruby
burningserenity has joined #ruby
jetchisel has joined #ruby
darthThorik_ has quit []
darthThorik_ has joined #ruby
darthThorik_ has quit [Client Quit]
darthThorik has joined #ruby
roadie has quit [Ping timeout: 260 seconds]
tau has quit [Ping timeout: 246 seconds]
burningserenity has quit [Ping timeout: 256 seconds]
Garb0_ has joined #ruby
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
Garb0 has quit [Ping timeout: 246 seconds]
TCZ has joined #ruby
orbyt_ has joined #ruby
ncakerlist has quit [Ping timeout: 265 seconds]
<al2o3-cr>
tanqueray 10 is some nice gin :)
CrazyEddy has quit [Ping timeout: 260 seconds]
<xco>
where is that defined? al2o3-cr
<xco>
:p
CrazyEddy has joined #ruby
<al2o3-cr>
xco: :) strong too.
<xco>
strong typed? is it a new programming language i haven't heard of? al2o3-cr
<xco>
:p
<xco>
tanqueray v10
<al2o3-cr>
it could be :{
<xco>
jokes aside, i don't like gins. i prefer vodka or whiskey
<xco>
al2o3-cr do you mix it with something or gulp it raw? al2o3-cr
<al2o3-cr>
in one xco, in one :)
<al2o3-cr>
gin and rum for me
<al2o3-cr>
not a lover of whiskey tbf
<xco>
rum is acceptable for me too
<xco>
i'll say gin is too hard core for me
<xco>
al2o3-cr by "in one" you mean shot like 50ml? :D :D or a whole bucket
<xco>
?
<xco>
damn! it's 47.3% alco
<al2o3-cr>
out of bottle swig, swig, swig :) haha
<xco>
oh my!
<apotheon>
I always thought gin tastes like Windex smells.
<xco>
ok this is really hard core
<xco>
apotheon hahahhaa :D :D
<al2o3-cr>
apotheon: is that windolene? if so, a little yes lol ;)
<apotheon>
Windex is a brand of window cleaner, probably the single most recognizable such brand in the US by an order of magnitude.
<xco>
al2o3-cr googled it, the bottle looks familiar, i'll try it just to have an idea what you're doing at home now
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<apotheon>
. . . so yeah, similar to Windolene, I guess.
nicholaslyang has joined #ruby
<apotheon>
I don't think I've ever seen Windolene in person.
dhollinger has joined #ruby
<apotheon>
I've only been in the UK for probably a week of cumulative time in my life.
<apotheon>
maybe a little more
yxhuvud has joined #ruby
<al2o3-cr>
xco: my party days are well and truly over ;)
<al2o3-cr>
apotheon: windolene use to come as a thick pinkish liquid. now it's like what you call windex.
<apotheon>
ah
<apotheon>
thin, blue, spray-bottle
<apotheon>
Windex
<al2o3-cr>
apotheon: sort of, yes.
<apotheon>
Windex is to window cleaner spray in the US as Kleenex is to "facial tissue" (disposable nose-blowers).
<apotheon>
. . . and as Frisbee is to "throwing disks".
<al2o3-cr>
yes, heard of all three.
<apotheon>
. . . and as Band-Aid is to self-adhesive bandages, and as Xerox is to copying machines . . .
teyas has quit [Read error: Connection reset by peer]
<al2o3-cr>
apotheon: plaster = band-aid
<al2o3-cr>
put a plaster on it lol ;)
<apotheon>
. . . and as Crock-Pot is to "slow cooker", and as Google is to websearch.
dhollinger has quit [Ping timeout: 256 seconds]
<al2o3-cr>
apotheon: why do the US still use imperial measurements.
<apotheon>
On a similar subject . . . in the late '90s (and into 2000s), Microsoft had internal official policy saying that nobody should use the word "navigate" to refer to clicking around to find stuff, and instead use "explore".
<apotheon>
That was because of the browser wars.
<apotheon>
al2o3-cr: because it's hard to break old habits
<al2o3-cr>
apotheon: ah, ok.
<apotheon>
There's also the fact that, in the US, it would be political suicide to try to make it punishable by incarceration or fines to use imperial measures in an official capacity anywhere.
<apotheon>
. . . though that may be changing.
<al2o3-cr>
apotheon: long time due
<apotheon>
It might get to the point where it's political suicide to *not* throw people in jail for the most asinine, trivial things.
<apotheon>
"You're going to jail for six years for using the phrase 'rule of thumb'."
<apotheon>
shit like that
<apotheon>
I'm opposed to governments throwing people in jail for shit like what system of measures they use.
<al2o3-cr>
lol, yeah.
<apotheon>
I'd rather people take a less forceful approach of trying to figure out how to get the culture to shift.
<apotheon>
. . . but these days, everyone wants to use the law for everything.
<apotheon>
When you say "There oughta be a law!" you should stop and consider whether you're okay with your grandmother (or some personal equivalent of the typical "your grandmother" idea) being killed for it.
<al2o3-cr>
apotheon: 100% agree
<apotheon>
someone generally harmless who you care about, in a nutshell
<apotheon>
kindly, et cetera
<al2o3-cr>
apotheon: take a breath dude!
<apotheon>
Hrm?
<al2o3-cr>
to many incomings/
<al2o3-cr>
but in horse racing they use metric?
<al2o3-cr>
beggars belief
jenrzzz has quit [Ping timeout: 265 seconds]
<al2o3-cr>
and we use furlong and feet lol
roadie has joined #ruby
<apotheon>
Well . . . I'm going off to do other things anyway.