{"action":"created","issue":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/1933","labels_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1933/labels{/name}","comments_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1933/comments","events_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1933/events","html_url":"https://github.com/bbatsov/rubocop/issues/1933","id":83580518,"number":1933,"title":"Style/RedundantSelf cop doesn't understand classes that use method_missing","user":{"login":"ifreecarve","id":583459,"avatar_url":"https://avatars.githubusercontent.com/u/583459?v=3","gravatar_id":"","url":"https://api.github.com/users/ifreecarve","html_url":"https://github.com/ifreecarve","followers_url":"https://api.github.com/users/ifreecarve/followers","following_url":"https://api.github.com/users/ifreecarve/following{/other_user}","gists_url":"https://api.github.com/users/ifreecarve/gists{/gist_id}","starred_url":"https://api.github.com/users/ifreecarve/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ifreecarve/subscriptions","organizations_url":"https://api.github.com/users/ifreecarve/orgs","repos_url":"https://api.github.com/users/ifreecarve/repos","events_url":"https://api.github.com/users/ifreecarve/events{/privacy}","received_events_url":"https://api.github.com/users/ifreecarve/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-06-01T16:09:08Z","updated_at":"2015-12-16T14:57:38Z","closed_at":null,"body":"The RedundantSelf cop doesn't check to see whether the uses of `self.` refer to something that does not exist in the class.  For example, classes that extend `ostruct` would need the `self.` in order to trigger the proper behavior -- the method_missing call which creates the necessary data structures.\r\n\r\nExample:\r\n\r\n```ruby\r\n\r\nrequire 'ostruct'\r\n\r\nclass MyStruct < OpenStruct\r\n\r\n  def initialize\r\n    self.right_way = OpenStruct.new\r\n    @wrong_way = OpenStruct.new\r\n  end  \r\n\r\nend\r\n\r\nms = MyStruct.new\r\nms.right_way.test1 = \"this functions correctly, but rubocop complains about it\"\r\nms.wrong_way.test2 = \"in `initialize': undefined method `test2=' for nil:NilClass (NoMethodError)\"\r\n```\r\n\r\nThe proper solution would seem to be ignoring instances of `self.` that do not refer to defined class methods or variables."},"comment":{"url":"https://api.github.com/repos/bbatsov/rubocop/issues/comments/165133185","html_url":"https://github.com/bbatsov/rubocop/issues/1933#issuecomment-165133185","issue_url":"https://api.github.com/repos/bbatsov/rubocop/issues/1933","id":165133185,"user":{"login":"alexdowad","id":1067359,"avatar_url":"https://avatars.githubusercontent.com/u/1067359?v=3","gravatar_id":"","url":"https://api.github.com/users/alexdowad","html_url":"https://github.com/alexdowad","followers_url":"https://api.github.com/users/alexdowad/followers","following_url":"https://api.github.com/users/alexdowad/following{/other_user}","gists_url":"https://api.github.com/users/alexdowad/gists{/gist_id}","starred_url":"https://api.github.com/users/alexdowad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexdowad/subscriptions","organizations_url":"https://api.github.com/users/alexdowad/orgs","repos_url":"https://api.github.com/users/alexdowad/repos","events_url":"https://api.github.com/users/alexdowad/events{/privacy}","received_events_url":"https://api.github.com/users/alexdowad/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T14:57:38Z","updated_at":"2015-12-16T14:57:38Z","body":"I would recommend you:\r\n\r\n- Add a UTF-8 encoding comment.\r\n- Add a comment for what `MyStruct` is about.\r\n- Remove the excess whitespace and extra empty lines.\r\n- Use a single-quoted string as suggested.\r\n- Split the long string over two lines rather than one.\r\n\r\nThen you are good to go!"}}