Sparkle formation has the habit of swallowing all typos, which makes debugging hard:
foo typo
dynanic! :bar
# ... builds
{
"typo": {},
"foo": "<#SparkleFormation::Struct",
"dymanic!": {"bar": {}}
}
let’s make these fail:
- no arguments or block
- looks like a method (start with _ or end with !)
# calling methods without arguments or blocks smells like a method missing
::SparkleFormation::SparkleStruct.prepend(Module.new do
def method_missing(name, *args, &block)
caller = ::Kernel.caller.first
called_without_args = (
args.empty? &&
!block &&
caller.start_with?(File.dirname(File.dirname(__FILE__))) &&
!caller.include?("vendor/bundle")
)
internal_method = (name =~ /^_|\!$/)
if called_without_args || internal_method
message = "undefined local variable or method `#{name}` (use block helpers if this was not a typo)"
::Kernel.raise NameError, message
end
super
end
end)