Skip to content

Instantly share code, notes, and snippets.

@shidel-dev
Last active August 29, 2015 14:07
Show Gist options
  • Save shidel-dev/6e3f1a9217de1dec5f89 to your computer and use it in GitHub Desktop.
Save shidel-dev/6e3f1a9217de1dec5f89 to your computer and use it in GitHub Desktop.
module Magic
def self.respond_to?(method_sym, include_private = false)
if method_sym.to_s =~ /^contains_(.*)/
true
else
super
end
end
def self.method_missing(m, *args, &block)
split_call = m.to_s.split('_')
if split_call[0] == "contains"
type_find(split_call[1].gsub("?", ''),args[0])
end
end
def self.type_find(klass, array)
array.any?{|item| item.class == to_class(klass.capitalize) }
end
def self.to_class(str)
Object.const_get(str)
end
end
#-----tests----
p Magic.contains_string?([1,2,7,'hello',95,3])
p Magic.contains_fixnum?(['a',4,'c','z'])
p Magic.contains_symbol(['hello', 4, Array.new, :cat])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment