Ruby TypeErrors involving `expected Data`
- by Kenny Peng
I've ran into situations where I have gotten these expected Data errors before, but they have always pointed to ActiveRecord not playing well with other libraries in the past. This piece of code:
def load(kv_block, debug=false)
# Converts a string block to a Hash using split
kv_map = StringUtils.kv_array_to_hash(kv_block)
# Loop through each key, value
kv_map.each do |mem,val|
# Format the member from camel case to underscore
member = mem.camel_to_underscore()
# If the object includes a method to set the key (i.e. the key
# is a member of self), invoke the method, setting the value of
# the member)
if self.methods.include?(member.to_set_method_name()) then # Exception thrown here
self.send(member.to_set_method_name(), val)
# Else, check for the same case, this time for an instance variable
elsif self.instance_variable_defined?(member.to_instance_var_name())
self.instance_variable_set(member.to_instance_var_name(), val)
# Else, complain that the object doesn't understand the key with
# respect to its class definition.
else
raise ArgumentError, "I don't know what to do with #{member}. #{self.class} does not have a member or function called #{member}"
end
end
end
produces the error wrong argument type #<Class:0x11a02088> (expected Data) (TypeError) in the each loop on the first if test. I've inspected a post-mortem debugging instance using rdebug, and running that line manually, it works without a hitch.
Has anyone seen this error before and what's been your solution to it? I used to think it was ActiveRecord and other gems stomping on each other's definitions, but I removed any references to ActiveRecord and this still occurs.