{"action":"created","issue":{"url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/35","labels_url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/35/comments","events_url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/35/events","html_url":"https://github.com/thirtysixthspan/descriptive_statistics/issues/35","id":102378444,"number":35,"title":"Gem is inconsistent with Rails methods which lead to really bad behavior.","user":{"login":"vmeyet","id":2462303,"avatar_url":"https://avatars.githubusercontent.com/u/2462303?v=3","gravatar_id":"","url":"https://api.github.com/users/vmeyet","html_url":"https://github.com/vmeyet","followers_url":"https://api.github.com/users/vmeyet/followers","following_url":"https://api.github.com/users/vmeyet/following{/other_user}","gists_url":"https://api.github.com/users/vmeyet/gists{/gist_id}","starred_url":"https://api.github.com/users/vmeyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmeyet/subscriptions","organizations_url":"https://api.github.com/users/vmeyet/orgs","repos_url":"https://api.github.com/users/vmeyet/repos","events_url":"https://api.github.com/users/vmeyet/events{/privacy}","received_events_url":"https://api.github.com/users/vmeyet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-21T13:19:15Z","updated_at":"2015-08-21T14:37:03Z","closed_at":null,"body":"Defining all the `DescriptiveStatistics ` methods on enumerable without namespacing whatsoever can lead to incompatibility with the Rails framework. Given that it is the most used framework in the community, I think this can lead to really nasty bugs.\r\n\r\nFor instance [Rails already define a method `sum` on `Enumerable`](http://api.rubyonrails.org/classes/Enumerable.html#method-i-sum), which is:\r\n\r\n```ruby\r\n# File activesupport/lib/active_support/core_ext/enumerable.rb, line 20\r\ndef sum(identity = 0, &block)\r\n  if block_given?\r\n    map(&block).sum(identity)\r\n  else\r\n    inject { |sum, element| sum + element } || identity\r\n  end\r\nend\r\n```\r\n\r\nand `DescriptiveStatistics#sum` is:\r\n\r\n```ruby\r\n  def sum(collection = self, &block)\r\n    values = Support::convert(collection, &block)\r\n    return DescriptiveStatistics.sum_empty_collection_default_value if values.empty?\r\n\r\n    return values.reduce(:+)\r\n  end\r\n```\r\n\r\nAs you can see the behaviour AND the signature is not the same.\r\nMost notably, in rails:\r\n```ruby\r\n[].sum # -> 0\r\n[].sum(3) # -> 3\r\n```\r\n\r\nin this gem:\r\n```ruby\r\n[].sum # -> nil\r\n[].sum(3) # -> NoMethodError: undefined method `each' for 3:Fixnum\r\n```\r\n\r\nthe `0` becoming `nil` is the most concerning for those using both Rails and this gem, since the bug can go undetected for quite a while.\r\n\r\nIn my opinion, the best approach would be either to namespace/prefix the methods, (or instead of including it as a mixin in Enumerable, having module functions but that's way more restrictive).\r\n\r\nWhat do you think of it? what do you think would be the best solution to it? "},"comment":{"url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/comments/133446651","html_url":"https://github.com/thirtysixthspan/descriptive_statistics/issues/35#issuecomment-133446651","issue_url":"https://api.github.com/repos/thirtysixthspan/descriptive_statistics/issues/35","id":133446651,"user":{"login":"thirtysixthspan","id":46311,"avatar_url":"https://avatars.githubusercontent.com/u/46311?v=3","gravatar_id":"","url":"https://api.github.com/users/thirtysixthspan","html_url":"https://github.com/thirtysixthspan","followers_url":"https://api.github.com/users/thirtysixthspan/followers","following_url":"https://api.github.com/users/thirtysixthspan/following{/other_user}","gists_url":"https://api.github.com/users/thirtysixthspan/gists{/gist_id}","starred_url":"https://api.github.com/users/thirtysixthspan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thirtysixthspan/subscriptions","organizations_url":"https://api.github.com/users/thirtysixthspan/orgs","repos_url":"https://api.github.com/users/thirtysixthspan/repos","events_url":"https://api.github.com/users/thirtysixthspan/events{/privacy}","received_events_url":"https://api.github.com/users/thirtysixthspan/received_events","type":"User","site_admin":false},"created_at":"2015-08-21T14:37:03Z","updated_at":"2015-08-21T14:37:03Z","body":"Thank you for submitting an issue. You are correct. There is a section in the readme concerning usage with Rails https://github.com/thirtysixthspan/descriptive_statistics#ruby-on-rails. The suggested practice there is to extend the DescriptiveStatistics module on a collection. Alternatively, you may access the module methods for use directly as described in the readme.\r\n\r\n"}}