I stumbled into this while struggling with this issue - but I guess this is more of a Ruby language-level inquiry.
I have a method that accepts four params:
def render_node_to_output(node, output, context, skip_output = false)
(For those who are curious, the method I'm talking about is Liquid::BlockBody::render_node_to_output of liquid:4.0.3 (on Linux, line 102 on gems/liquid-4.0.3/lib/liquid/block_body.rb).)
Right at the start of the method, I inspect the first three variables as:
p node
p output
p context
print("\n\n")
This method is being invoked repeatedly by different components, and at some points I get the error:
/root/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/jekyll-3.8.5/lib/jekyll/filters.rb:292:in `inspect': wrong number of arguments (given 0, expected 1) (ArgumentError)
from /root/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:105:in `inspect'
from /root/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:105:in `p'
from /root/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/liquid-4.0.3/lib/liquid/block_body.rb:105:in `render_node_to_output'
Apparently the context variable is going into some "non-existent" (?) state at some point.
I tried adding print(context.class) and print(context) right before p context, and they do display the same, acceptable values for both success and failure scenarios: Liquid::Context and #<Liquid::Context:0x00007fffd43d9948>.
My queries:
- why does
inspectsay it didn't receive an argument when I clearly passed it one? More importantly, why does this happen only for some values ofcontext? AFAIK even ifcontextwerenil,inspectshould not fail (ruby -e "x = nil; p x"producesnil). I couldn't find any references as to why or wheninspectcould behave in this manner. - what is the correct way to skip such "bad" states of
contextso that I can at least continue inspecting "good" values without breaking the program at the first "bad" state - ideally without using a try-catch strategy?
(I am pretty new to Ruby, so apologies if I missed/misused any jargon.)