{"action":"created","issue":{"url":"https://api.github.com/repos/lotus/controller/issues/106","labels_url":"https://api.github.com/repos/lotus/controller/issues/106/labels{/name}","comments_url":"https://api.github.com/repos/lotus/controller/issues/106/comments","events_url":"https://api.github.com/repos/lotus/controller/issues/106/events","html_url":"https://github.com/lotus/controller/issues/106","id":75612299,"number":106,"title":"Lotus::Utils::Hash conflicts with ActiveSupport::HashWithIndifferentAccess.new","user":{"login":"weppos","id":5387,"avatar_url":"https://avatars.githubusercontent.com/u/5387?v=3","gravatar_id":"","url":"https://api.github.com/users/weppos","html_url":"https://github.com/weppos","followers_url":"https://api.github.com/users/weppos/followers","following_url":"https://api.github.com/users/weppos/following{/other_user}","gists_url":"https://api.github.com/users/weppos/gists{/gist_id}","starred_url":"https://api.github.com/users/weppos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weppos/subscriptions","organizations_url":"https://api.github.com/users/weppos/orgs","repos_url":"https://api.github.com/users/weppos/repos","events_url":"https://api.github.com/users/weppos/events{/privacy}","received_events_url":"https://api.github.com/users/weppos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-12T13:54:55Z","updated_at":"2015-05-12T16:07:06Z","closed_at":null,"body":"First of all, let me say that I'm reporting the issue as it is (since it took me a while to understand what was going on) and it may not necessarily be an issue on your side. However, I'd like to start the discussion to figure out what is the best approach here.\r\n\r\nI have an object, which performs some Hash manipulation. The input is a controller parameter, and since I'm using both Rails and Lotus, the object can be either a Lotus `Params` instance or a `Hash` (in case of Rails).\r\n\r\nTo avoid incompatibilities, the initializer calls `to_h` on the input, to make sure to work with a simple hash rather subclasses or specific implementations.\r\n\r\n```ruby\r\nclass ContactParams\r\n  def initialize(params)\r\n    @params = params.to_h\r\n  end\r\n\r\n  def to_h\r\n    @params.slice(...)\r\n  end\r\nend\r\n```\r\n\r\nTo make sure I can always reference the `Hash` with a symbol, but to bypass the symbol GC issue in Rails < 2.2 I'm using the `ActiveSupport::HashWithIndifferentAccess.new` class.\r\n\r\n```\r\nclass ContactParams\r\n  def initialize(params)\r\n    @params = ActiveSupport::HashWithIndifferentAccess.new(params.to_h)\r\n  end\r\nend\r\n```\r\n\r\nHere comes the problem. Have a look at this console log\r\n\r\n```\r\n(byebug)  ActiveSupport::HashWithIndifferentAccess.new(Lotus::Utils::Hash.new({ foo: \"bar\" }))\r\n{}\r\n(byebug) ActiveSupport::HashWithIndifferentAccess.new({ foo: \"bar\" })\r\n{\"foo\"=>\"bar\"}\r\n```\r\n\r\nBecause `params.to_h` returns an instance of `Lotus::Utils::Hash` and not `Hash`, when the instance is passed to `HashWithIndifferentAccess`, for some reason the resulting object is `{}` (the values are wiped out).\r\n\r\nAs I mentioned, I still need to debug at which level the values are lost and who is the guilty."},"comment":{"url":"https://api.github.com/repos/lotus/controller/issues/comments/101332193","html_url":"https://github.com/lotus/controller/issues/106#issuecomment-101332193","issue_url":"https://api.github.com/repos/lotus/controller/issues/106","id":101332193,"user":{"login":"jodosha","id":5089,"avatar_url":"https://avatars.githubusercontent.com/u/5089?v=3","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"created_at":"2015-05-12T16:07:06Z","updated_at":"2015-05-12T16:07:06Z","body":"@weppos That means when you'll upgrade to MRI 2.2, you won't use AS anymore, but only invoke `#to_h` on the argument?\r\n\r\nRegardless of your answer, I still think it's a good idea to let both `Params` and `Utils::Hash` implementations of `#to_h` to return an instance of `Hash`."}}