Skip to content

Instantly share code, notes, and snippets.

@aalavandhan
Last active August 29, 2015 14:10
Show Gist options
  • Save aalavandhan/cfcb9ba76fb923e8b6ed to your computer and use it in GitHub Desktop.
Save aalavandhan/cfcb9ba76fb923e8b6ed to your computer and use it in GitHub Desktop.
class ArrayInquirer < Array
private
def method_missing method, *args
begin
any? { |elem| elem.to_s == method[0..-2] }
rescue NoMethodError
super method, *args
end
end
end
module ArrayInquiry
def inquiry
ArrayInquirer.new(self)
end
end
Array.send(:include, ArrayInquiry)
# ["code", "brahma"].inquiry.code? => true
# ["code", "brahma"].inquiry.brahma? => true
# ["code", "brahma"].inquiry.really? => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment