Re:Ruby 3.2.0 Is from Another Dimension
by lcnPylGDnU4H9OF on Wednesday January 04, 2023 @06:05PM
(#34253265)
> I hate that I can't easy determine where a given method of an arbitrary object is defined.
https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debugger...
The relevant bit is under the heading:
> I’m calling a method, but I don’t know where it goes
def index
p method(:render).source_location
render params[:id]
end
It sounds like this is the answer to your monkey-patching woes. my_object.method(:my_method).source_location # returns path/to/file:[line number]
One thing I think Ruby gets right is the naming convention for methods that modify the object they're called on (<obj>.<method>!) and callables in general that return a boolean (<callable>?).
My biggest gripe with Ruby is the class implementation. I find metaclasses a bit more difficult to understand in Ruby. I hate that I can't easy determine where a given method of an arbitrary object is defined.
I recall that it wasn't uncommon for popular libraries to "open up" a class that was an integral part of Rails and redefine methods, overriding the original implementation. I recall trying to figure out why the method I was calling wasn't returning the value I expected, even after reading the Rails source. Come to find out, some random library had overridden it. They'd matched the behavior of a previous Rails version, but the Rails behavior had since changed. I spent hours on that specific problem and still resent it to this day :P.