Skip to content

Instantly share code, notes, and snippets.

@dlt
Created January 6, 2012 14:11
Show Gist options
  • Save dlt/1570778 to your computer and use it in GitHub Desktop.
Save dlt/1570778 to your computer and use it in GitHub Desktop.
C = Class.new do
def has?(methods)
!!methods.split(".").inject(self) do |object, method|
object.respond_to?(method) && object.send(method)
end
end
end
c = C.new
c.has?("methods") # => true
c.has?("methods.reverse") # => true
c.has?("methods.reverse.first") # => true
c.has?("methods.reverse.foo") # => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment