Skip to content

Instantly share code, notes, and snippets.

@elia
Created July 5, 2012 17:59
Show Gist options
  • Select an option

  • Save elia/3055246 to your computer and use it in GitHub Desktop.

Select an option

Save elia/3055246 to your computer and use it in GitHub Desktop.
module Kernel
def p *args
`console.log.apply(console, args)`
end
end
class Array
def -(other)
reject { |i| other.include? i }
end
end
class Element
def up selector
parent = `#{jquery}.parents(#{selector})[0] || nil`
Element.new(parent) if parent
end
def down selector
child = `#{jquery}.find(#{selector})[0] || nil`
Element.new(child) if child
end
def [] name
`#{jquery}.attr(#{name})`
end
def data name
`#{jquery}.data(#{name}) || nil`
end
def jquery
@jquery ||= `$(#{@el})`
end
def visible?
`#{jquery}.is(':visible')`
end
attr_reader :el
alias to_s inspect
def class_names
class_name.strip.split(/\s+/)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment