jhass[m] changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 3.1.2, 3.0.4, 2.7.6: https://www.ruby-lang.org | Paste 4+ lines to: https://gist.github.com | Books: https://goo.gl/wpGhoQ
taiju has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Rounin has quit [Ping timeout: 252 seconds]
some14u has joined #ruby
hightower3 has joined #ruby
hightower2 has quit [Ping timeout: 265 seconds]
eddof13 has joined #ruby
plujon has quit [Ping timeout: 265 seconds]
eddof13 has quit [Client Quit]
John_Ivan has quit [Ping timeout: 244 seconds]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
fercell has joined #ruby
fercell has quit [Ping timeout: 264 seconds]
Starfoxxes has quit [Ping timeout: 265 seconds]
Starfoxxes has joined #ruby
Starfoxxes has quit [Max SendQ exceeded]
ur5us has quit [Ping timeout: 244 seconds]
some14u has joined #ruby
<leftylink> hmmmmmmmmmmmmmmmm I dunno...
<leftylink> pandabot: rb @dyn = {}.freeze; def self.method_missing(a, *args); args.empty? && @dyn.key?(a) ? @dyn[a] : super end; def dyn(h) old = @dyn.freeze; @dyn = @dyn.merge(h); yield.tap { @dyn = old } end; f = -> { a }; [dyn(a: 1998, &f), dyn(a: 8, &f), dyn(a: 19, &f)]
<pandabot> [1998, 8, 19] - https://carc.in/#/r/drng
kale has joined #ruby
<leftylink> probably better to be explicit about which vars you want to be dynamic, so that you don't have to do this method_missing
<leftylink> hmm
<leftylink> am I supposed to pronounce "dyn" like "din" or "dine"... it should probably be the latter
Starfoxxes has joined #ruby
<leftylink> the current concept seems to need method_missing, though I wonder if I can do it without using the name @dyn
<leftylink> but the method_missing and the dyn function have to share that information somehow don't they...
<libsys> gr33n7007h: that works... but what if I wanted to pass a param to the lambda?
<libsys> something like: obj = MyClass.new; obj.instance_exec(&proc(**params))
<libsys> I need to execute a proc as if it were executed inside the instance of an object
<adam12> libsys: Untested, but could try passing as first arg. obj.instance_exec(**params, &proc)
<gr33n7007h> libsys: yes, like adam12 said.
<gr33n7007h> >> Object.new.instance_exec(:foo, &-> (n) { p self: self, arg: n})
<ruby[bot]> gr33n7007h: # => (https://carc.in/#/r/drnk)
<libsys> nice... that works
<libsys> thanks a lot guys
<libsys> now... that looks like a high level of wizardry to me... where can I find more information about that?
<leftylink> pandabot: rb def dyn(dynvar, &b) Object.new.tap { |o| o.define_singleton_method(:method_missing) { |nam, *args| args.empty? && dynvar.key?(nam) ? dynvar[nam] : super } }.instance_eval(&b) end; f = ->_ { a }; [dyn(a: 8, &f), dyn(a: 19, &f)]
<pandabot> [8, 19] - https://carc.in/#/r/drno
<leftylink> excellent, I got what I wanted. no more @dyn, just a local, and that's fine
<leftylink> of course, still have to use method_missing, but I think that is unavoidable
<libsys> (about the & symbol to execute a proc in current context)
<leftylink> there is no such thing. https://ruby-doc.org/core-2.7.0/doc/syntax/calling_methods_rdoc.html#label-Proc+to+Block+Conversion "You can convert a proc or lambda to a block argument with the & (block conversion) operator:"
<leftylink> that's all the & is doing
<libsys> nice
<libsys> I love ruby a bit more now
<libsys> <3
<adam12> heh
<leftylink> another example of "the best way to get help is to say something wrong rather than to ask a question"?
darkstardevx has joined #ruby
darkstardevx has quit [Remote host closed the connection]
darkstardevx has joined #ruby
<leftylink> it's only logical
<leftylink> saying an obvious falsehood like "it executes a proc in the current context" would quickly get shot down and therefore get the response of what it actually does
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ur5us has joined #ruby
cocalero has joined #ruby
ssh0732 has quit [Ping timeout: 258 seconds]
jhass has quit [Ping timeout: 268 seconds]
jetchisel has joined #ruby
jhass has joined #ruby
fercell has joined #ruby
Guimauve has joined #ruby
fercell has quit [Ping timeout: 260 seconds]
taiju has quit [Ping timeout: 268 seconds]
darkstardevx has quit [Read error: Connection reset by peer]
darkstardevx has joined #ruby
cocalero has quit [Quit: Going offline, see ya! (www.adiirc.com)]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
<leftylink> though I had to make f take a _ arg because self gets passed to the block... it's a little unergonomic. wonder what I can do about that
<leftylink> obviously not a problem if I just pass a block
jetchisel has quit [Quit: Unfortunately time is always against us -- [Morpheus]]
<leftylink> this is such a fruitless idea though. I would never advocate actually doing this. I think at the most if I was going to have something with dynamic scope I would require that all accesses declare that they expect the scope to be dynamic, otherwise you just can't understand the code
<leftylink> but I think for now we're just exploring what's possible, without regard to whether it's a good idea
<leftylink> oh and of course another disadvantage is that because it's using method_missing lexically-scoped stuff takes precedence
jpn has joined #ruby
Guest38 has joined #ruby
Guest38 has quit [Client Quit]
<leftylink> although the alternative doesn't help there! if a variable and a function have the same name the variable wins
<leftylink> pandabot: rb def dyn(dynvar, &b) Object.new.tap { |o| dynvar.each { |k, v| o.define_singleton_method(k) { v } } }.instance_eval(&b) end; f = ->_ { a }; [dyn(a: 8, &f), dyn(a: 0) { dyn(a: 19, &f) }]
<pandabot> [8, 19] - https://carc.in/#/r/drnt
<leftylink> so there was never a need for method_missing
Guimauve has quit [Quit: Client closed]
<leftylink> but defining a method with the given name is basically how rspec let does its thing, as can be seen in https://github.com/rspec/rspec-core/blob/fa1b5f5849ac0efe4ffab7d3d1a4e1cf87951541/lib/rspec/core/memoized_helpers.rb#L306
<leftylink> and of course rspec let is dynamically scoped variable
<littlebuddy> Hi! I have a `Sites` model (subdomain-based multi-tenancy using ActsAsTenant) which has many `Categories` which has many `Posts`.
<littlebuddy> From my `Posts#index` root route I would like to do `Post.where(site: current_tenant)` except `Post` isn't associated with `Site`, only `Category` is.
<littlebuddy> Is there a way to do this without having to add `belongs_to :site` to `Post`?
swaggboi has quit [Ping timeout: 244 seconds]
ur5us has quit [Remote host closed the connection]
ur5us has joined #ruby
ur5us has quit [Ping timeout: 250 seconds]
Inoperable has quit [Quit: All your buffer are belong to us!]
swaggboi has joined #ruby
Inoperable has joined #ruby
robotmay has quit [Ping timeout: 268 seconds]
tankf33der has joined #ruby
nirvdrum has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
skuntee4 has quit [Ping timeout: 260 seconds]
jpn has quit [Ping timeout: 265 seconds]
ur5us has joined #ruby
jpn has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
nirvdrum has joined #ruby
nirvdrum has quit [Ping timeout: 268 seconds]
fercell has joined #ruby
fercell has quit [Ping timeout: 265 seconds]
protektwar has quit [Ping timeout: 250 seconds]
jpn has quit [Ping timeout: 268 seconds]
Rounin has joined #ruby
Sankalp has quit [Ping timeout: 250 seconds]
ruralscientist has quit [Remote host closed the connection]
ruralscientist has joined #ruby
ur5us has quit [Ping timeout: 268 seconds]
jpn has joined #ruby
sylario has joined #ruby
jpn has quit [Ping timeout: 265 seconds]
robotmay has joined #ruby
fercell has joined #ruby
nirvdrum has joined #ruby
nirvdrum has quit [Client Quit]
fercell has quit [Ping timeout: 244 seconds]
dionysus69 has joined #ruby
ruralscientist has quit [Remote host closed the connection]
ruralscientist has joined #ruby
Al2O3 has quit [Ping timeout: 244 seconds]
ruralscientist has quit [Remote host closed the connection]
ruralscientist has joined #ruby
hightower3 has quit [Remote host closed the connection]
nirvdrum has joined #ruby
hightower2 has joined #ruby
teclator has joined #ruby
hightower2 has quit [Remote host closed the connection]
mikecmpbll has quit [Ping timeout: 244 seconds]
mikecmpbll has joined #ruby
jpn has joined #ruby
ruralscientist has quit [Remote host closed the connection]
fercell has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
protektwar has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
fercell has quit [Ping timeout: 250 seconds]
moldorcoder7 has joined #ruby
hightower2 has joined #ruby
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #ruby
dionysus69 has quit [Ping timeout: 244 seconds]
caleb has quit [Remote host closed the connection]
hwrd has quit [Remote host closed the connection]
g_sg has quit [Remote host closed the connection]
KOTP has quit [Remote host closed the connection]
graemefawcett has quit [Remote host closed the connection]
Bounga has quit [Write error: Broken pipe]
tsujp has quit [Remote host closed the connection]
alexisg has quit [Remote host closed the connection]
matta has quit [Remote host closed the connection]
srushe has quit [Write error: Broken pipe]
graemefawcett has joined #ruby
srushe has joined #ruby
alexisg has joined #ruby
matta has joined #ruby
KOTP has joined #ruby
g_sg has joined #ruby
caleb has joined #ruby
tsujp has joined #ruby
Bounga has joined #ruby
hwrd has joined #ruby
dionysus69 has joined #ruby
nirvdrum has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
weaksauc_ has joined #ruby
weaksauce has quit [Ping timeout: 268 seconds]
dionysus69 has quit [Ping timeout: 264 seconds]
Al2O3 has joined #ruby
protektwar has quit [Ping timeout: 250 seconds]
perrierjouet has joined #ruby
smp has quit [Quit: ZNC 1.8.2 - https://znc.in]
smp has joined #ruby
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
<rapha> adam12: half-way through the talk and i'm thinking, wow, this is why i never felt at home in Rails, or even capable of really doing something with it, and what made me get out of web apps entirely.
<rapha> unfortunately there's a lot of language being used that makes it difficult to understand. will have to do some research of those terms and then watch again.
jpn has quit [Ping timeout: 252 seconds]
Tempesta has quit [Quit: See ya!]
jpn has joined #ruby
Tempesta has joined #ruby
Sankalp has joined #ruby
nirvdrum has joined #ruby
nirvdrum_ has joined #ruby
dionysus69 has joined #ruby
nirvdrum has quit [Ping timeout: 268 seconds]
nirvdrum_ has quit [Quit: nirvdrum_]
nirvdrum has joined #ruby
perdent has joined #ruby
some14u has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
some14u has quit [Ping timeout: 252 seconds]
perdent has quit [Quit: Client closed]
perdent has joined #ruby
nirvdrum has joined #ruby
nirvdrum has quit [Client Quit]
jpn has quit [Ping timeout: 268 seconds]
some14u has joined #ruby
perdent has quit [Quit: Client closed]
some14u has quit [Ping timeout: 268 seconds]
perdent has joined #ruby
jpn has joined #ruby
fercell has joined #ruby
fercell has quit [Ping timeout: 268 seconds]
nirvdrum has joined #ruby
fercell has joined #ruby
John_Ivan has joined #ruby
fercell has quit [Ping timeout: 260 seconds]
gr33n7007h has quit [Quit: WeeChat 3.6]
Rounin has quit [Remote host closed the connection]
gr33n7007h has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
dionysus69 has quit [Ping timeout: 268 seconds]
szkl has joined #ruby
nirvdrum has joined #ruby
dionysus69 has joined #ruby
some14u has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
<littlebuddy> Hi! I have a `Sites` model (subdomain-based multi-tenancy using https://github.com/ErwinM/acts_as_tenant) which has many `Categories` which has many `Posts`. From my `Posts#index` root route I would like to do `Post.where(site: current_tenant)` except `Post` isn't associated with `Site`, only `Category` is. Is there a way to do this without having to add `belongs_to :site` to `Post`? Otherwise all my
<littlebuddy> separate multisites will share the same content :(
Laplace has joined #ruby
<Laplace> Hey folks -- How can I 'override' a method in Ruby while providing a different method to call it? For example, how do I change the behaviour of `to_s` while still providing `old_to_s`
<Laplace> I want to override `to_s` for a class, while still providing an escape hatch to use the "regular behaviour"
nirvdrum has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Laplace> I think I have a solution. I think what I'll do is just call super_method to_s
TomyWork has joined #ruby
dorian has quit [Ping timeout: 268 seconds]
some14u has joined #ruby
some14u has quit [Client Quit]
protektwar has quit [Ping timeout: 268 seconds]
<adam12> Laplace: alias_method or alis
<adam12> err, alias
<adam12> alias_method :original_to_s, :to_s
<adam12> littlebuddy: Can you use a has_many through? It's been a while since I've done Rails.
<adam12> rapha: Using doctrine of useful objects has been one of the better things I've adopted in recent memory. It makes a crazy amount of sense, tho there is some boilerplate that you have to do.
<littlebuddy> adam12: Looks like it, yep!
nirvdrum has quit [Quit: nirvdrum]
Al2O3 has quit [Ping timeout: 255 seconds]
nirvdrum has joined #ruby
nirvdrum has quit [Client Quit]
<rapha> adam12: yes, he talks about that, too, like, the boilerplate fallacy where people come to expect, "oh, has_many :somethings, just one line of code, how simple", but it's actually not. i don't know your background but i haven't formally studied CS or anything, so there's a lot of mental concepts they seem to be building upon, so for me this has so far been a bit of a journey down the proverbial rabbit
<rapha> hole ... exciting though, feeling a bit like alice.
nirvdrum has joined #ruby
Al2O3 has joined #ruby
<adam12> rapha: Lately I've preferred boilerplate over not. If I reach for a gem, I generally regret it because it might churn and cause work for me. So typing it out has been nice. And juniors understand it more.
<adam12> ie. for Doctrine of Usable Objects, you might end up with a similar `self.configure` method in every object. `instance = new; receiver.some_method = instance`. And you can automate that out, but it's kind of nice just having it there in plain view.
<adam12> Here's a smaller class from my distributed DNS cloud that kind of demonstrates it. https://gist.github.com/adam12/db4f109feb48cf20ebe4180f71823029
nirvdrum has quit [Quit: nirvdrum]
<adam12> Many classes have a super similar `configure` method. And I've thought about "DRYing" it up, but I just can't forgive the simplicity of it.
nirvdrum has joined #ruby
* rapha takes a peek not knowing much about DNS or clouds other than that they're beautiful when made of water vapor
<rapha> hmm ok
<rapha> i'll keep that open while watching the video again next time
<adam12> LOL. This example is simple; it just makes calls using Faraday. But I inject the conn (Faraday connection) as a dependency since Faraday supports mocks and I can inject a Mocked conn too.
<adam12> It's kind of similar to James Shore's Nullable Infrastructure, or testing without mocks.
<rapha> see that's that thing with the terminology
<rapha> i can infer that Faraday must be another piece of software from the uppercase R
<rapha> F i mean
<rapha> but then "mocks" and "inject" and "Mocked", wow, now it's going over the top of my head again
<rapha> same as with the Doctrine videos
<rapha> need to go slow with this but it has a very interesting flavour to it
<adam12> rapha: Ah, sorry. Faraday is an HTTP client wrapper for Ruby that's been around a long time.
nirvdrum has quit [Client Quit]
<rapha> and by mock you mean "not real just made-up"?
some14u has joined #ruby
some14u has quit [Client Quit]
<adam12> rapha: Right. It's not _really_ a HTTP client, but it looks like one, and might act like one all the way up to making the HTTP request to the Internet. But then it might return a fake response as if it did.
<rapha> okay
<rapha> that's nice for webscraping without bothering admins
<rapha> like, while you still work on it :)
<adam12> rapha: Yeah! When I've done that in the past, I might `wget -m` to get a local copy of part of the site, then point my scraper at that while i debug it. Maybe only a few pages.
nirvdrum has joined #ruby
nirvdrum has quit [Quit: nirvdrum]
nirvdrum has joined #ruby
fercell has joined #ruby
Inoperable has quit [Excess Flood]
fercell has quit [Ping timeout: 252 seconds]
Inoperable has joined #ruby
some14u has joined #ruby
some14u has quit [Client Quit]
eddof13 has joined #ruby
mikecmpbll has quit [Read error: Connection reset by peer]
sgt_chuckles has joined #ruby
mikecmpbll has joined #ruby
<sgt_chuckles> i have some rspec trests that run in circleci job to check acceptance criteria for files in a certain folder, but don't want them to run if no changes are detected in the folder.
<sgt_chuckles> is there a way to make a spec pass automatically on a condition, skipping all other tests?
some14u has joined #ruby
some14u has quit [Client Quit]
nirvdrum has quit [Quit: nirvdrum]
Laplace has quit [Quit: Connection closed for inactivity]
fercell has joined #ruby
some14u has joined #ruby
fercell has quit [Ping timeout: 264 seconds]
moldorcoder7 has quit [Quit: %bye mirc%]
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
moldorcoder7 has joined #ruby
jpn has quit [Quit: Lost terminal]
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_ht has joined #ruby
TomyWork has quit [Quit: Leaving]
<adam12> sgt_chuckles: What about wrapping them all in a giant if statement?
<adam12> sgt_chuckles: rspec supports `:if => condition`, so could look at that too.
<sgt_chuckles> it tells me that all tests were skipped
<sgt_chuckles> "All examples were filtered out"
protektwar has quit [Quit: No Ping reply in 180 seconds.]
protektwar has joined #ruby
protektwar has quit [Changing host]
protektwar has joined #ruby
jvalleroy has quit [Ping timeout: 268 seconds]
jvalleroy has joined #ruby
Inoperable has quit [Excess Flood]
Inoperable has joined #ruby
protektwar has quit [Ping timeout: 268 seconds]
smp has quit [Ping timeout: 250 seconds]
smp has joined #ruby
Rounin has joined #ruby
some14u has joined #ruby
<sgt_chuckles> is there a way to make all other examples pass if one specific example fails?
teclator has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
cocalero has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
szkl has quit [Quit: Connection closed for inactivity]
some14u has joined #ruby
some14u has quit [Client Quit]
some14u has joined #ruby
some14u has quit [Client Quit]
perdent has quit [Quit: Client closed]
sgt_chuckles has quit [Quit: Client closed]
John_Ivan has quit [Ping timeout: 260 seconds]
dionysus69 has quit [Ping timeout: 265 seconds]
perdent has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
nirvdrum has joined #ruby
nirvdrum has quit [Ping timeout: 268 seconds]
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #ruby
eddof13 has joined #ruby
_ht has quit [Remote host closed the connection]
hightower2 has quit [Remote host closed the connection]
hightower2 has joined #ruby
ur5us has joined #ruby
sgt_chuckles has joined #ruby
some14u has joined #ruby
nirvdrum has joined #ruby
mahler has joined #ruby
nirvdrum has quit [Ping timeout: 268 seconds]
nirvdrum has joined #ruby
nirvdrum has quit [Client Quit]
John_Ivan has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eddof13 has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sgt_chuckles has quit [Quit: Client closed]
eddof13 has joined #ruby
eddof13 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jetchisel has joined #ruby
perdent has quit [Quit: Client closed]
reset has quit [Ping timeout: 265 seconds]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
Rounin has quit [Ping timeout: 252 seconds]
henninb has joined #ruby
some14u has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sylario has quit [Quit: Connection closed for inactivity]