The rules of Ruby's super
keyword is that if it is called without arguments, all of the original arguments are forwarded. If it is called with explicit arguments, the explicit arguments are exclusively passed in.
In this example, arguments should never be forwarded, since I am calling super
with exact arguments.
Example:
@doc = Nokogiri::HTML::DocumentFragment.parse("<body></body>")
class Cat < Nokogiri::XML::Node
def initialize(arg1, arg2)
super("cat", arg2) # Pass arg2 to super
# Do something with arg1 later
end
end
When calling: Cat.new("dog", @doc)
I expect to get back a <cat></cat>
tag, and I expect the first argument to be ignored. Instead I am getting a <dog></dog>
tag.
Is there a reason this case would defy expected behavior?