Say I have
class A
end
class B < A
end
p B.superclass.superclass.superclass # => BasicObject
Instead of calling .superclass 3 times, is there some way I can specify something like a repeat operator which will basically say call this method x times?
This is how it is done
3.times.reduce(B) {|a, _| a.superclass } # => BasicObject
I made it as below :
([:superclass]*3).inject(B,:send)
# => BasicObject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With