awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.08k stars 454 forks source link

format error when printing new object #271

Closed dhurba87 closed 6 years ago

dhurba87 commented 8 years ago

I realized that when I print my object it throws following errors,

ArgumentError - wrong number of arguments (given 1, expected 0): (gem) awesome_print-1.7.0/lib/awesome_print/formatter.rb:122:in convert_to_hash' (gem) awesome_print-1.7.0/lib/awesome_print/formatter.rb:55:inawesome_self' (gem) awesome_print-1.7.0/lib/awesome_print/formatter.rb:36:in format' (gem) awesome_print-1.7.0/lib/awesome_print/inspector.rb:148:inunnested' (gem) awesome_print-1.7.0/lib/awesome_print/inspector.rb:115:in awesome' (gem) awesome_print-1.7.0/lib/awesome_print/formatters/array_formatter.rb:27:inblock (2 levels) in format' (gem) awesome_print-1.7.0/lib/awesome_print/indentator.rb:13:in indent' (gem) awesome_print-1.7.0/lib/awesome_print/inspector.rb:104:inincrease_indentation' (gem) awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:111:in indented' (gem) awesome_print-1.7.0/lib/awesome_print/formatters/array_formatter.rb:26:inblock in format' (gem) awesome_print-1.7.0/lib/awesome_print/formatters/array_formatter.rb:23:in format' (gem) awesome_print-1.7.0/lib/awesome_print/formatter.rb:79:inawesome_array' (gem) awesome_print-1.7.0/lib/awesome_print/formatter.rb:34:in format' (gem) awesome_print-1.7.0/lib/awesome_print/inspector.rb:148:inunnested' (gem) awesome_print-1.7.0/lib/awesome_print/inspector.rb:115:in awesome' (gem) awesome_print-1.7.0/lib/awesome_print/formatters/hash_formatter.rb:31:inblock (2 levels) in format'

but inspect still gives useful output:

MachineShop::Rules:0x303cad4 JSON: {"id":"5721b427c80dd4c45f00006d","_id":"5721b427c80dd4c45f00006d","active":true,"cloud_rule":false,"created_at":"2016-04-28T06:56:39+00:00","data_source_ids":["5722002c67804cb15d0000be"],"data_source_type_ids":[],"deleted_at":null,"description":"test rule description","downstream_rule_id":null,"last_run_status":"pass","plain_english":"If is always true then send a POST request to 9843621770. Otherwise do nothing. This rule applies to these device instances: teste test tes.","then_actions":[{"id":"57cfadb8f1f17942dc0000a2","_id":"57cfadb8f1f17942dc0000a2","action_frequency":null,"body_template":"dfadfa dfad fadfa dfadfadfa dfadf a","clear":true,"created_at":"2016-09-07T06:03:36+00:00","deleted_at":null,"headers":{"Accept":"application/json"},"last_run":"1970-01-01T00:00:00+00:00","method":"post","priority":1,"send_to":"9843621770","updated_at":"2016-09-07T06:03:36+00:00","type":"http_request_rule_action"}],"updated_at":"2016-09-07T06:03:36+00:00","user_id":"57109072c80dd49a1f00008b","rule_condition":{"id":"57cfadb8f1f17942dc0000a1","_id":"57cfadb8f1f17942dc0000a1","created_at":"2016-09-07T06:03:36+00:00","deleted_at":null,"parent_or_sibling_key":null,"parent_or_sibling_value":null,"property":"","rule_id":"5721b427c80dd4c45f00006d","updated_at":"2016-09-07T06:03:36+00:00","value":"","type":"true_rule_condition"},"http_code":200}

gerrywastaken commented 8 years ago

That's a strange one: https://github.com/awesome-print/awesome_print/blob/v1.7.0/lib/awesome_print/formatter.rb#L122

Not sure which method this is referring to when it mentions that we are passing an additional argument.

gerrywastaken commented 8 years ago

@dhurba87 Oh wait... does MachineShop::Rules create a method or instance method called "method"? If so, that's a bad idea. We expect method to be https://ruby-doc.org/core-2.3.1/Object.html#method-i-method, which takes a symbol as an argument.