havenwood changed the topic of #ruby to: Rules & more: https://ruby-community.com | Ruby 2.7.1, 2.6.6, 2.5.8: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.de/ and select Ruby as the language | Rails questions? Ask in #RubyOnRails | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | Can't talk? Register/identify with Nickserv first!
davispuh has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
davispuh has joined #ruby
chris__ has joined #ruby
nicholaslyang has joined #ruby
chris__ has quit [Ping timeout: 264 seconds]
jottr has joined #ruby
jottr_ has quit [Ping timeout: 260 seconds]
cloaked1 has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
imode has quit [Ping timeout: 256 seconds]
ScottFrancis has quit [Ping timeout: 256 seconds]
bambanx has joined #ruby
garyserj has quit [Read error: Connection reset by peer]
barg has joined #ruby
TomyWork has quit [Remote host closed the connection]
TomyWork has joined #ruby
chris____ has joined #ruby
chris____ has quit [Ping timeout: 240 seconds]
inradius has quit [Remote host closed the connection]
jottr_ has joined #ruby
jottr has quit [Ping timeout: 264 seconds]
ScottFrancis has joined #ruby
teej has quit [Ping timeout: 240 seconds]
itok has quit [Ping timeout: 256 seconds]
mattwc has quit [Ping timeout: 246 seconds]
gorsuch has quit [Ping timeout: 258 seconds]
gmcintire has quit [Ping timeout: 265 seconds]
darthThorik_ has quit [Read error: Connection reset by peer]
MentalPower has quit [Ping timeout: 258 seconds]
pitastrudl has quit [Ping timeout: 265 seconds]
ScottFrancis has quit [Client Quit]
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ScottFrancis has joined #ruby
Mutsuhito has quit [Ping timeout: 244 seconds]
ScottFrancis has quit [Remote host closed the connection]
gitter1234 has quit [Ping timeout: 256 seconds]
ScottFrancis has joined #ruby
redlegion has quit [Ping timeout: 244 seconds]
fowlduck has quit [Ping timeout: 260 seconds]
pyrmont has quit [Ping timeout: 258 seconds]
zipkid has quit [Ping timeout: 258 seconds]
ScottFrancis_ has joined #ruby
ScottFrancis_ has quit [Client Quit]
ScottFrancis has quit [Client Quit]
itok has joined #ruby
nicholaslyang has joined #ruby
jimeh has quit [Read error: Connection reset by peer]
itok has quit [Max SendQ exceeded]
jimeh has joined #ruby
amidesx has joined #ruby
Mutsuhito has joined #ruby
gitter1234 has joined #ruby
pitastrudl has joined #ruby
zipkid has joined #ruby
nicholaslyang has quit [Client Quit]
redlegion has joined #ruby
gorsuch has joined #ruby
pyrmont has joined #ruby
MentalPower has joined #ruby
itok has joined #ruby
SeepingN has joined #ruby
teej has joined #ruby
gmcintire has joined #ruby
fowlduck has joined #ruby
darthThorik_ has joined #ruby
amidesx has left #ruby [#ruby]
mattwc has joined #ruby
bambanx has quit [Ping timeout: 264 seconds]
kripher has joined #ruby
chris____ has joined #ruby
kripher has quit [Quit: Leaving]
codefriar has quit [Ping timeout: 246 seconds]
nicholaslyang has joined #ruby
codefriar has joined #ruby
al2o3-cr has quit [Quit: WeeChat 2.8]
al2o3-cr has joined #ruby
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
davispuh has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
gix- has quit [Ping timeout: 260 seconds]
nicholaslyang has joined #ruby
jottr_ has quit [Ping timeout: 264 seconds]
cmdshepard has joined #ruby
jottr_ has joined #ruby
jottr_ has quit [Ping timeout: 246 seconds]
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
cmdshepard has quit [Quit: Leaving]
SeepingN has quit [Quit: The system is going down for reboot NOW!]
chris____ has quit [Remote host closed the connection]
chalkmonster has quit [Quit: WeeChat 2.8]
jottr_ has joined #ruby
jottr_ has quit [Ping timeout: 246 seconds]
chalkmonster has joined #ruby
nicholaslyang has joined #ruby
imode has joined #ruby
chalkmonster has quit [Quit: WeeChat 2.8]
chris____ has joined #ruby
chris____ has quit [Ping timeout: 246 seconds]
jottr_ has joined #ruby
Garb0 has quit [Ping timeout: 246 seconds]
chalkmonster has joined #ruby
darkstardev13 has joined #ruby
jottr_ has quit [Ping timeout: 240 seconds]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
chalkmonster has quit [Quit: WeeChat 2.8]
jottr_ has joined #ruby
jottr_ has quit [Ping timeout: 258 seconds]
TomyWork has quit [Ping timeout: 244 seconds]
plutes has quit [Ping timeout: 272 seconds]
plutes has joined #ruby
ChmEarl has quit [Quit: Leaving]
rafadc has quit [Ping timeout: 265 seconds]
rafadc has joined #ruby
ur5us has quit [Ping timeout: 260 seconds]
zululee_1 has joined #ruby
rafadc has quit [Quit: ZNC - https://znc.in]
zululee_ has quit [Ping timeout: 260 seconds]
zululee_1 is now known as zululee_
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
rafadc has joined #ruby
nicholaslyang has joined #ruby
funnel has quit [Ping timeout: 258 seconds]
chris__ has joined #ruby
genpaku has quit [Ping timeout: 272 seconds]
_whitelogger has joined #ruby
chris__ has quit [Ping timeout: 264 seconds]
TomyWork has joined #ruby
TomyWork has quit [Remote host closed the connection]
chris__ has joined #ruby
ldepandis has joined #ruby
sauvin has joined #ruby
dviola has quit [Quit: WeeChat 2.8]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
conta has quit [Remote host closed the connection]
conta has joined #ruby
chris__ has quit [Remote host closed the connection]
conta has quit [Quit: conta]
conta has joined #ruby
cd has quit [Quit: cd]
schne1der has joined #ruby
imode has quit [Ping timeout: 264 seconds]
nicholaslyang has joined #ruby
gitter1234 has quit [Quit: Connection closed for inactivity]
dionysus69 has joined #ruby
postmodern has quit [Read error: Connection reset by peer]
postmodern has joined #ruby
nicholaslyang has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
conta has quit [Quit: conta]
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
doomlist3 has joined #ruby
doomlist3 has quit [Ping timeout: 256 seconds]
rprimus has quit [Ping timeout: 272 seconds]
rprimus has joined #ruby
venmx has joined #ruby
GodFather has quit [Ping timeout: 246 seconds]
conta has joined #ruby
Sina has joined #ruby
ur5us has joined #ruby
Jonopoly has joined #ruby
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
Jonopoly has quit [Quit: WeeChat 2.8]
Jonopoly has joined #ruby
xco has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
xco has joined #ruby
Jonopoly has quit [Client Quit]
Jonopoly has joined #ruby
postmodern has quit [Ping timeout: 246 seconds]
AndreYuhai has joined #ruby
Jonopoly has quit [Quit: WeeChat 2.8]
Jonopoly has joined #ruby
ellcs1 has joined #ruby
<AndreYuhai> When I use unique key for my columns, how can I return the existing record when .new is called with the existing record's values?
<AndreYuhai> I did this: https://dpaste.org/2cwz
<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.
siery has quit [Ping timeout: 272 seconds]
siery has joined #ruby
<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
<havenwood> doomlist3: 2.step(by: 3)
<havenwood> doomlist3: (2..) % 3
<havenwood> &>> (2..) % 3
<rubydoc> # => ((2..).%(3)) (https://carc.in/#/r/99ao)
<havenwood> &>> 2.step(by: 3)
<rubydoc> # => (2.step(by: 3)) (https://carc.in/#/r/99ap)
<havenwood> doomlist3: If you show the input and your desired output, we might have better suggestions.
<havenwood> &>> a = [*1..10]; a.each_slice(3).first # doomlist3
<rubydoc> # => [1, 2, 3] (https://carc.in/#/r/99aq)
<doomlist3> [1,2,3,4,5].step( from 2 : to 5 : step 2) just like in python
Jonopoly has quit [Ping timeout: 246 seconds]
<havenwood> doomlist3: You obviously can't just use Python code verbatim in Ruby.
<doomlist3> i described what step i am talking about
<havenwood> doomlist3: You've shown psuedo code, but you missed the part where you show the result you want.
<havenwood> doomlist3: [1,2,3,4,5].step( from 2 : to 5 : step 2) #=> ???
<havenwood> doomlist3: Just show the return value you want.
<al2o3-cr> havenwood: that'd be [3,5] in python.
<havenwood> al2o3-cr: :D
<havenwood> al2o3-cr: Been a while since I've used Python.
<al2o3-cr> yeah, me too :P
<doomlist3> l=[0,1,2,3,4,5,6,7] from index 1 to index 6 , step=2. l[1] = 1 ... l[1+2], l[3+2],...
<doomlist3> l[1] to l[6] say => [1,3,5,]
<doomlist3> NoMethodError (undefined method `step' for [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]:Array)
<havenwood> zverok was trying to get a Python-like sytax there.
<doomlist3> ok sorry .slice
<havenwood> doomlist3: [1,2,3,4,5].each_slice(3).map(&:last)
<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.
leah2 has quit [Ping timeout: 260 seconds]
<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]
impermanence has quit [Quit: Connection closed]
leah2 has joined #ruby
<al2o3-cr> doomlist3: just for a bit of fun: https://gist.github.com/gr33n7007h/a0161d6705092bb48a4e7b9ae8124716
<al2o3-cr> if you're home sick :)
<doomlist3> i never wanted a pythonic solution in ruby, but thanks
jottr_ has quit [Quit: WeeChat 2.8]
<al2o3-cr> i know you really did.
<doomlist3> 'string'.to_a error
<doomlist3> can't convert string to array
<havenwood> doomlist3: 'string'.grapheme_clusters
<doomlist3> 'hi'.to_i converted to int "hi" what the heck
<doomlist3> 'this'.to_f
<doomlist3> => 0.0
<doomlist3> this is some kind of a sick joke
<havenwood> doomlist3: What would you like? An error? `nil`?
<al2o3-cr> doomlist3: if there's not a valid number at the start of the string return 0. do you even read the docs.
<havenwood> doomlist3: There are three ways you might want it. Permissive, exacting and harsh, or exacting but graceful.
<doomlist3> it's supposed to say can't convert string to int, as "apple" can't be converted to int
<havenwood> doomlist3: Then you want: Integer("apple")
<havenwood> doomlist3: You're just doing it wrong. Instead of assuming Ruby is broken, just ask!
<havenwood> doomlist3: We're happy to show you how we do it in Ruby.
<havenwood> &>> Integer("apple")
<rubydoc> stderr: -e:4:in `Integer': invalid value for Integer(): "apple" (ArgumentError)... check link for more (https://carc.in/#/r/99as)
<havenwood> &>> Integer("apple", exception: false)
<rubydoc> # => nil (https://carc.in/#/r/99at)
<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.
<havenwood> AndreYuhai: object.method(:exists?).parameters
romanlevin has quit [Ping timeout: 246 seconds]
<havenwood> AndreYuhai: Or it's often nice to just check the code.
<havenwood> AndreYuhai: object.method(:exists?).source_location
<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')
<AndreYuhai> havenwood, User.joins(:user_identifier).find_by(user_identifiers: {name: 'foo'}) *
schne1der has quit [Ping timeout: 265 seconds]
<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 :)
r29v has joined #ruby
Kilo`byte has joined #ruby
r29v has quit [Client Quit]
rtyler has quit [Quit: ZNC - https://znc.in]
Mia has joined #ruby
ryanar has quit [Quit: Textual IRC Client: www.textualapp.com]
Axy has quit [Ping timeout: 260 seconds]
gavlee has quit []
birkbeggar has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
gavlee has joined #ruby
doomlist3 has quit [Ping timeout: 256 seconds]
birkbeggar has joined #ruby
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
howdoi has joined #ruby
rtyler has joined #ruby
nicholaslyang has joined #ruby
birkbeggar has quit [Quit: Textual IRC Client: www.textualapp.com]
nicholaslyang has quit [Client Quit]
doomlist3 has joined #ruby
nicholaslyang has joined #ruby
nicholaslyang has quit [Client Quit]
TCZ has quit [Quit: Leaving]
nicholaslyang has joined #ruby
tau has joined #ruby
tau has joined #ruby
tau has quit [Changing host]
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
<teyas> (https://gist.github.com/tejasInSiberia/3d1bc1fea155f0be214fb35bd66e1735) (Please uncomment the # private_class_method line to run the code)
<teyas> Please suggest
<havenwood> teyas: Those are instance methods, not class methods.
<havenwood> teyas: You can make them private with: private
<havenwood> teyas: Either `private def Quill` or `def Quill; #...; end; private :quill` or `private; def Quill; #...; end
<teyas> havenwood: you mean "private_class_method" is a static function ? I messed up
<havenwood> teyas: These aren't class methods, they're instance methods.
<havenwood> teyas: For example, `def Tony` is an instance method.
<havenwood> teyas: Every method you've defined in this gist is an instance method.
<teyas> havenwood: yeh. got it
<havenwood> If you choose a `.rb` file extension for a gist it'll do nice syntax highlighting.
<havenwood> ?tabs teyas
<havenwood> Ruby community standards recommend using 2 spaces as indentation (see https://github.com/bbatsov/ruby-style-guide#spaces-indentation and https://ukupat.github.io/tabs-or-spaces/).
<havenwood> Switch from hard tabs to two-space soft tabs.
<havenwood> Oh, this is soft 4 space. Heh.
<havenwood> teyas: private :Groot
<teyas> havenwood: similarly, is there any other way of making the inner class private ? instead of using private_constant
<havenwood> teyas: #private_constant is the correct way, but it's not typical to hide classes. It's more often used for constant variables.
<teyas> havenwood: I want to hide classes, because I dont want anything to spill outside this file. need to enforce it
<havenwood> teyas: Then #private_constant is correct.
<havenwood> teyas: I'd suggest a linter. Consider using RuboCop.
<havenwood> teyas: gem install rubocop
<havenwood> teyas: Then let it automatically lint your file: rubocop -a
<teyas> havenwood: rubocop is beautification right ?
<teyas> havenwood: I mean, no functional impact as such
davispuh has joined #ruby
ncakerlist has joined #ruby
doomlist3 has quit [Ping timeout: 264 seconds]
<teyas> havenwood: I use camelCase for variables... can't help old habits. Now trying with private :Groot
poro has joined #ruby
Deesl has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<teyas> havenwood: private :Groot hides it for the outer class too.. so will need to expose it via another public method ??
<ncakerlist> in slices when is 0 based indexing superior over 1 based
Deesl has joined #ruby
<ncakerlist> for strings
Deesl has quit [Client Quit]
leitz has quit [Quit: Leaving]
burningserenity has quit [Ping timeout: 256 seconds]
Deesl has joined #ruby
FastJack has quit [Ping timeout: 260 seconds]
<leftylink> ahhhhhhh you know, this reminds me of the time in uni when my TA handed out to the class a copy of https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html (dijkstra's writing in favour of starting at 0)
FastJack has joined #ruby
<leftylink> I, too, enjoy the fact that the first element of a.drop(N) will be a[N]
<leftylink> that has helped me in the past
xco has joined #ruby
burningserenity has joined #ruby
dhollinger has quit [Ping timeout: 265 seconds]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<xco> never got to understand the "red" marks under this timeline https://gyazo.com/5c470a9fda8bf027d57670ba23743478
<xco> what do they mean?
<xco> i'd like to know when Array#split was added to rails
<xco> why did i take a screenshot when i can post the link? https://apidock.com/rails/Array/split 🤦🏾‍♂️
poro has quit [Quit: Leaving]
Garb0 has joined #ruby
<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.
ur5us has quit [Ping timeout: 256 seconds]
teyas has joined #ruby
postmodern has joined #ruby
Garb0_ is now known as Garb0
roadie has quit [Ping timeout: 260 seconds]
roadie has joined #ruby
TCZ has quit [Quit: Leaving]
roadie has quit [Ping timeout: 272 seconds]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
Garb0_ has joined #ruby
Garb0 has quit [Ping timeout: 256 seconds]
siery has joined #ruby
cd has quit [Ping timeout: 256 seconds]
poro has joined #ruby
AndreYuhai has quit [Quit: Leaving]
troulouliou_div2 has quit [Remote host closed the connection]
cd has joined #ruby
DTZUZU_ has joined #ruby
DTZUZU has quit [Ping timeout: 246 seconds]
ldepandis has joined #ruby
roadie has joined #ruby
jenrzzz has joined #ruby
teyas has quit [Quit: Leaving]
jenrzzz has quit [Ping timeout: 256 seconds]
jenrzzz has joined #ruby
troulouliou_div2 has joined #ruby
roadie has quit [Ping timeout: 256 seconds]
poro has quit [Quit: Leaving]
troulouliou_div2 has quit [Remote host closed the connection]
Deesl has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
drincruz has quit [Ping timeout: 240 seconds]
ldepandis has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dhollinger has joined #ruby
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
handojin has joined #ruby
snuz has quit [Read error: Connection reset by peer]
troulouliou_div2 has joined #ruby
rmnull has joined #ruby
snuz has joined #ruby
akem has quit [Quit: Leaving]
stryek has quit [Quit: Connection closed for inactivity]
DTZUZU_ is now known as DTZUZU
diegospb has joined #ruby
diegospb has quit [Remote host closed the connection]
greengriminal has quit [Quit: Leaving]
drincruz has joined #ruby
CrazyEddy has quit [Ping timeout: 264 seconds]
CrazyEddy has joined #ruby
greengriminal has joined #ruby
drincruz has quit [Ping timeout: 240 seconds]
akem has joined #ruby
greengriminal has quit [Quit: Leaving]