I programmed myself into a corner and thought of a fix involving
alias_method... when I tried to implement the fix, I discovered that I'm
really confused about how alias_method works.
Take the following code:
class A
def initialize
puts "A0"
end
end
class B < A
def initialize
super
puts "B0"
end
end
class A # Add some functionality to A
alias_method :__initialize__, "initialize"
def initialize x
__initialize__
puts "A1"
end
end
class B
end
So, now:
B.new 5 # --> A0\nA1
The first time I wrote this, I tried copying from the Axe book:
...
alias_method :__initialize__, :initialize.inspect
...
but this gives me a "undefined method `:initialize' for class `A'" error.
Why? "class A ; puts :initialize.inspect ; end" works, so I'd expect
:initialize.inpect as a method argument for alias_method to work, too. This
illustrates my confusion that :initialize.inspect --> ":initialize", but
alias_method is expecting "initialize" here.
Thanks,
--- SER