Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Remove varargs from in 4 0 stable #10397

Merged
merged 2 commits into from

2 participants

@BMorearty

Same diff as rails/rails#10394, but for 4-0-stable. Please discuss on that pull request, not this one.

BMorearty added some commits
@BMorearty BMorearty Revert "Object#in? also accepts multiple parameters"
This reverts commit ebf69ab.

`in?` must not take multiple parameters because its behavior would be
ambiguous:

    # Test if "B" is included in a list of names with `"B".in?(*names)`:
    names = ["BMorearty"]
    "B".in?(*names)   # => true

    names = ["BMorearty","rubyduo"]
    "B".in?(*names)   # => false

Conflicts:
	activesupport/lib/active_support/core_ext/object/inclusion.rb
	activesupport/test/core_ext/object/inclusion_test.rb
88eb1a8
@BMorearty BMorearty Revert the guide after removing varargs from `in?`. 275a064
@rafaelfranca rafaelfranca merged commit a8ef0bb into from
@carlosantoniodasilva carlosantoniodasilva referenced this pull request from a commit in carlosantoniodasilva/rails
@carlosantoniodasilva carlosantoniodasilva Revert "Merge pull request #10397 from BMorearty/remove-varargs-from-…
…in-4-0-stable"

This reverts commit a8ef0bb, reversing
changes made to 1296adb.

Reason: Partially revert this commit and properly deprecate #in? with
multiple arguments in 4-0.
c273cb6
@carlosantoniodasilva carlosantoniodasilva referenced this pull request from a commit
@carlosantoniodasilva carlosantoniodasilva Revert "Merge pull request #10397 from BMorearty/remove-varargs-from-…
…in-4-0-stable"

This reverts commit a8ef0bb, reversing
changes made to 1296adb.

Reason: Partially revert this commit and properly deprecate #in? with
multiple arguments in 4-0.
c6ef49f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 1, 2013
  1. @BMorearty

    Revert "Object#in? also accepts multiple parameters"

    BMorearty authored
    This reverts commit ebf69ab.
    
    `in?` must not take multiple parameters because its behavior would be
    ambiguous:
    
        # Test if "B" is included in a list of names with `"B".in?(*names)`:
        names = ["BMorearty"]
        "B".in?(*names)   # => true
    
        names = ["BMorearty","rubyduo"]
        "B".in?(*names)   # => false
    
    Conflicts:
    	activesupport/lib/active_support/core_ext/object/inclusion.rb
    	activesupport/test/core_ext/object/inclusion_test.rb
  2. @BMorearty
This page is out of date. Refresh to see the latest.
View
28 activesupport/lib/active_support/core_ext/object/inclusion.rb
@@ -1,25 +1,15 @@
class Object
- # Returns true if this object is included in the argument(s). Argument must be
- # any object which responds to +#include?+ or optionally, multiple arguments can be passed in. Usage:
+ # Returns true if this object is included in the argument. Argument must be
+ # any object which responds to +#include?+. Usage:
#
- # characters = ['Konata', 'Kagami', 'Tsukasa']
- # 'Konata'.in?(characters) # => true
+ # characters = ["Konata", "Kagami", "Tsukasa"]
+ # "Konata".in?(characters) # => true
#
- # character = 'Konata'
- # character.in?('Konata', 'Kagami', 'Tsukasa') # => true
- #
- # This will throw an ArgumentError if a single argument is passed in and it doesn't respond
+ # This will throw an ArgumentError if the argument doesn't respond
# to +#include?+.
- def in?(*args)
- if args.length > 1
- args.include? self
- else
- another_object = args.first
- if another_object.respond_to? :include?
- another_object.include? self
- else
- raise ArgumentError.new 'The single parameter passed to #in? must respond to #include?'
- end
- end
+ def in?(another_object)
+ another_object.include?(self)
+ rescue NoMethodError
+ raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
end
end
View
10 activesupport/test/core_ext/object/inclusion_test.rb
@@ -2,16 +2,6 @@
require 'active_support/core_ext/object/inclusion'
class InTest < ActiveSupport::TestCase
- def test_in_multiple_args
- assert :b.in?(:a,:b)
- assert !:c.in?(:a,:b)
- end
-
- def test_in_multiple_arrays
- assert [1,2].in?([1,2],[2,3])
- assert ![1,2].in?([1,3],[2,1])
- end
-
def test_in_array
assert 1.in?([1,2])
assert !3.in?([1,2])
View
3  guides/source/active_support_core_extensions.md
@@ -476,12 +476,11 @@ NOTE: Defined in `active_support/core_ext/kernel/reporting.rb`.
### `in?`
-The predicate `in?` tests if an object is included in another object or a list of objects. An `ArgumentError` exception will be raised if a single argument is passed and it does not respond to `include?`.
+The predicate `in?` tests if an object is included in another object. An `ArgumentError` exception will be raised if the argument passed does not respond to `include?`.
Examples of `in?`:
```ruby
-1.in?(1,2) # => true
1.in?([1,2]) # => true
"lo".in?("hello") # => true
25.in?(30..50) # => false
Something went wrong with that request. Please try again.