Re:Friendly Attributes Pattern in Ruby
by montroser on Saturday November 08, 2025 @11:38AM
(#45857970)
Ah, that's good to know! Yeah, he was wrong about a lot of stuff, so that adds up. He ended up in jail for a stint.
Re:Friendly Attributes Pattern in Ruby
by jaredcwhite on Saturday November 08, 2025 @11:51AM
(#45858070)
whoa
Re:Friendly Attributes Pattern in Ruby
by bradgessler on Saturday November 08, 2025 @12:26PM
(#45858342)
Quite the plot twist there
Re:Friendly Attributes Pattern in Ruby
by radanskoric on Saturday November 08, 2025 @12:32PM
(#45858386)
Woah, this thread escalated quickly.
you monkeypatch over core methods like that they put you in jail right away no trial, no nothing. Metaprogrammers... we have a special jail for metaprogrammers. You're global variabling? Right to jail. You're using for loops instead of iterators? To jail right away. You're type checking by class... Jail. Abusing eval? Jail. You're using global variables like a drunken sailor? You right to Jail. You overuse class variables Jail. You underuse class variables believe it or not jail. You use too many tests also Jail, overuse underuse. You use define method and you could have created the methods explicitly? Believe it or not, jail right away. We have the best code monkeys in the world because of jail.
how does this work if i import two different gems that both monkeypatch the same classes?
Even if you can see the source, it still seems difficult to understand where the monkeypatch came from if you have transitive dependencies and whatnot.
The last one wins
No, he is in fact correct. Rails used to be full of code such as the following, though I now see that they actually annotate code generated at Rails startup runtime with the file and the line of at least the call to the code generator [0].
There is even a fucking issue on the ruby-lang issue tracker from two years ago griping about this dark corner of the language [1].
No matter though, I don't expect average laymen to delve into this level of detail nor assess the veracity of statements at this layer.
Most Rubyists at this point are at the level of "terminal dumbfuck," and are indistinguishable from a bartender who stumbled into a 16 week bootcamp for blockchain development. The one silver lining of the great AI Happening is that these people will be put back into their place.
irb(main):001\* class Foo
irb(main):002" class_eval <<-RB
irb(main):003" def foobar()
irb(main):004" puts "foobar"
irb(main):005" end
irb(main):006\* RB
irb(main):007> end
=> :foobar
irb(main):008> Foo.new
=> #<Foo:0x00007ff5c1a8c190>
irb(main):009> Foo.new.method(:foobar)
=> #<Method: Foo#foobar() (eval at (irb):2):1>
irb(main):010> Foo.new.method(:foobar).source_location
=> ["(eval at (irb):2)", 1]
[0] https://github.com/rails/rails/blob/9b054c66d4fc5ec526cff356...
Look, I'm not a big fan of all of Rails' monkeypatching. That's why I don't use Rails anymore, I use other Ruby frameworks like Bridgetown, Roda, and Hanami. But there's definitely a way to dive into the "magic" and find out what's going on.