Skip to content

Instantly share code, notes, and snippets.

@oakbow
Created January 28, 2015 07:59
Show Gist options
  • Save oakbow/7229d343cf34c02957b1 to your computer and use it in GitHub Desktop.
Save oakbow/7229d343cf34c02957b1 to your computer and use it in GitHub Desktop.
Object.in?でArgumentErrorが発生した場合の対処(Rails3 => Rails4) ref: http://qiita.com/Oakbow/items/f1d3f2b69fd056488162
ArgumentError - wrong number of arguments (2 for 1):
# 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
#
# This will throw an ArgumentError if the argument doesn't respond
# to +#include?+.
def in?(another_object)
another_object.include?(self)
rescue NoMethodError
raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
end
object.in?('hogehogehoge', 'fugafugafuga')
object.in?(['hogehogehoge', 'fugafugafuga'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment