{"action":"closed","issue":{"url":"https://api.github.com/repos/tj/terminal-table/issues/47","labels_url":"https://api.github.com/repos/tj/terminal-table/issues/47/labels{/name}","comments_url":"https://api.github.com/repos/tj/terminal-table/issues/47/comments","events_url":"https://api.github.com/repos/tj/terminal-table/issues/47/events","html_url":"https://github.com/tj/terminal-table/issues/47","id":55541376,"number":47,"title":"Monkeypatching \"left\" in String conflicts with Active Record","user":{"login":"norman","id":5042,"avatar_url":"https://avatars.githubusercontent.com/u/5042?v=3","gravatar_id":"","url":"https://api.github.com/users/norman","html_url":"https://github.com/norman","followers_url":"https://api.github.com/users/norman/followers","following_url":"https://api.github.com/users/norman/following{/other_user}","gists_url":"https://api.github.com/users/norman/gists{/gist_id}","starred_url":"https://api.github.com/users/norman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/norman/subscriptions","organizations_url":"https://api.github.com/users/norman/orgs","repos_url":"https://api.github.com/users/norman/repos","events_url":"https://api.github.com/users/norman/events{/privacy}","received_events_url":"https://api.github.com/users/norman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-26T21:39:25Z","updated_at":"2015-04-13T21:20:24Z","closed_at":"2015-04-13T21:20:24Z","body":"I recently had to track down a problem with a Rails application where a query was failing and isolated it to this code in Active Record:\r\n\r\n```ruby\r\ncounts = table_joins.map do |join|\r\n  if join.is_a?(Arel::Nodes::StringJoin)\r\n    # Table names + table aliases\r\n    join.left.downcase.scan(\r\n      /join(?:\\s+\\w+)?\\s+(\\S+\\s+)?#{quoted_name}\\son/\r\n    ).size\r\n  elsif join.respond_to? :left\r\n    join.left.table_name == name ? 1 : 0\r\n  else\r\n    0\r\n  end\r\nend\r\n```\r\n\r\nSince terminal_table aliases `String#ljust`, to `left`, any instance of String responds to `left` when using this gem. In the example above this leads to an ArgumentError. This happens to me on Rails 4.0.12, but I've verified that similar code exists in Rails 4.2.0 as well. To reproduce, create a scope with a manual join, and then invoke the `exists?` method on the scope. For example:\r\n\r\n```ruby\r\nclass Foo < ActiveRecord::Base\r\n  belongs_to :bar\r\n  scope :baz, -> {joins('INNER JOIN bars on bars.id = foos.bar_id')}\r\nend\r\n\r\nFoo.baz.exists?(1)\r\n```\r\n\r\nI would suggest removing the aliases in `String` completely and using the `ljust` and `rjust` methods internally instead; `left` is a very generic method name to add to a core class like String and is likely to conflict with other libraries as well.\r\n"}}