{"action":"created","issue":{"url":"https://api.github.com/repos/cucumber/gherkin/issues/173","repository_url":"https://api.github.com/repos/cucumber/gherkin","labels_url":"https://api.github.com/repos/cucumber/gherkin/issues/173/labels{/name}","comments_url":"https://api.github.com/repos/cucumber/gherkin/issues/173/comments","events_url":"https://api.github.com/repos/cucumber/gherkin/issues/173/events","html_url":"https://github.com/cucumber/gherkin/pull/173","id":140490595,"number":173,"title":"Ruby: Use require instead of require_relative","user":{"login":"maximeg","id":252162,"avatar_url":"https://avatars.githubusercontent.com/u/252162?v=3","gravatar_id":"","url":"https://api.github.com/users/maximeg","html_url":"https://github.com/maximeg","followers_url":"https://api.github.com/users/maximeg/followers","following_url":"https://api.github.com/users/maximeg/following{/other_user}","gists_url":"https://api.github.com/users/maximeg/gists{/gist_id}","starred_url":"https://api.github.com/users/maximeg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maximeg/subscriptions","organizations_url":"https://api.github.com/users/maximeg/orgs","repos_url":"https://api.github.com/users/maximeg/repos","events_url":"https://api.github.com/users/maximeg/events{/privacy}","received_events_url":"https://api.github.com/users/maximeg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-13T14:39:39Z","updated_at":"2016-03-13T22:03:19Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cucumber/gherkin/pulls/173","html_url":"https://github.com/cucumber/gherkin/pull/173","diff_url":"https://github.com/cucumber/gherkin/pull/173.diff","patch_url":"https://github.com/cucumber/gherkin/pull/173.patch"},"body":"The **gherkin** ruby gem use at various place `require_relative` to require other files from the gem.\r\n\r\nAs it happens that these files can be (and in fact are also) required by `require` elsewhere (for example directly in **cucumber-core**), this causes a discrepancy leading to these files being loaded twice.\r\n\r\nIndeed, my ruby setup using rbenv on OS X relies on the fact that the main exposed directory for ruby is `/usr/local/opt/rbenv/versions/2.3.0/lib/ruby` which is a symbolic link for `/usr/local/Cellar/rbenv/1.0.0/versions/2.3.0/lib` (standard Homebrew + rbenv setup).\r\n\r\nSo `require 'gherkin/token_matcher'` ends up loading `/usr/local/opt/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/token_matcher.rb` (once, even if required several times, due to the fact that require loads file once per path)\r\nwhereas in the **gherkin** gem `require_relative 'token_matcher'` resolves to `require '/usr/local/Cellar/rbenv/1.0.0/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/token_matcher.rb'`, different from the previous version, and so, is loaded another time.\r\n\r\nThese are the warnings that annoyed me (and made me looking into it :laughing:) : \r\n```\r\n➜ cucumber\r\n/usr/local/Cellar/rbenv/1.0.0/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/token_matcher.rb:6: warning: already initialized constant Gherkin::TokenMatcher::LANGUAGE_PATTERN\r\n/usr/local/opt/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/token_matcher.rb:6: warning: previous definition of LANGUAGE_PATTERN was here\r\n/usr/local/opt/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/dialect.rb:4: warning: already initialized constant Gherkin::DIALECT_FILE_PATH\r\n/usr/local/Cellar/rbenv/1.0.0/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/dialect.rb:4: warning: previous definition of DIALECT_FILE_PATH was here\r\n/usr/local/opt/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/dialect.rb:5: warning: already initialized constant Gherkin::DIALECTS\r\n/usr/local/Cellar/rbenv/1.0.0/versions/2.3.0/lib/ruby/gems/2.3.0/gems/gherkin-3.2.0/lib/gherkin/dialect.rb:5: warning: previous definition of DIALECTS was here\r\nUsing the default profile...\r\n[...]\r\n```\r\n\r\nThis humble PR aims to fix this :smiley:."},"comment":{"url":"https://api.github.com/repos/cucumber/gherkin/issues/comments/196061390","html_url":"https://github.com/cucumber/gherkin/pull/173#issuecomment-196061390","issue_url":"https://api.github.com/repos/cucumber/gherkin/issues/173","id":196061390,"user":{"login":"tooky","id":349,"avatar_url":"https://avatars.githubusercontent.com/u/349?v=3","gravatar_id":"","url":"https://api.github.com/users/tooky","html_url":"https://github.com/tooky","followers_url":"https://api.github.com/users/tooky/followers","following_url":"https://api.github.com/users/tooky/following{/other_user}","gists_url":"https://api.github.com/users/tooky/gists{/gist_id}","starred_url":"https://api.github.com/users/tooky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tooky/subscriptions","organizations_url":"https://api.github.com/users/tooky/orgs","repos_url":"https://api.github.com/users/tooky/repos","events_url":"https://api.github.com/users/tooky/events{/privacy}","received_events_url":"https://api.github.com/users/tooky/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T22:03:19Z","updated_at":"2016-03-13T22:03:19Z","body":"I'm not so sure now. I was under the impression that you didn't get the caching with require_relative that you do with require, but I think I'm wrong. \r\n\r\nThis is a great article https://practicingruby.com/articles/ways-to-load-code explaining how it all works. \r\n\r\nI wonder if this isn't actually a ruby gems bug? The symlink'd dir is really the same dir, and it would be nice if rubygems realised that? WDYT?"}}