Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Array functionality with two 'include' methods. #2671

Closed
wants to merge 1 commit into from
Closed

Extend Array functionality with two 'include' methods. #2671

wants to merge 1 commit into from

Conversation

butcher
Copy link
Contributor

@butcher butcher commented Aug 24, 2011

This new functionality for Array instances. Two methods that help check inclusion two o more values. I think it will be very helpful for developers, because you can write your code shorter.

@fxn
Copy link
Member

fxn commented Aug 24, 2011

As a rule of thumb, the driver for AS core extensions is Rails itself. In that sense, AS core extensions have a different goal than other libraries like facets.

So albeit these and other extensions may be found to be useful for some in practice, they have to prove to be useful for the implementation of Rails generally speaking (unless they are clear winners for common idioms in web applications).

Do you think there are places in Rails where these extensions could be used?

@pixeltrix
Copy link
Contributor

On a technical note you can pass the block to any? and all? and not create an intermediate array, e.g:

def include_all?(*args)
  args.all?{ |i| self.include?(i) }
end

def include_any?(*args)
  args.any?{ |i| self.include?(i) }
end

Also why only Array? The include? method is part of Enumerable so it should go there. However what @fxn said is correct.

@pixeltrix
Copy link
Contributor

A quick grep across the Rails source code reveals only one instance where an any? or an all? contains an include? simple enough to use include_any? or include_all?.

@butcher
Copy link
Contributor Author

butcher commented Aug 24, 2011

@pixeltrix you are right about replacing this methods in Enumerable module.
You also right about passing blocks to any?
But I disagree with opinion about using methods. Some methods from time/calculation.rb never used in rails but very helpful for developers who works with Time in projects.
I think maybe this methods must be implemented in ruby core....

@fxn
Copy link
Member

fxn commented Aug 24, 2011

What's useful for most web applications most of the times is more debatable. And some existing extensions may be counterexamples.

But as I said it is a rule of thumb. A rule of thumb that helps keeping AS core extensions under control, otherwise AS would evolve into facets which is definitely not the goal.

There has been a lot of extensions that could be useful theoretically, but didn't fit in the criteria for being in AS. I believe this proposal falls here. Thanks for preparing the patch nonetheless.

@fxn fxn closed this Aug 24, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants