Skip to content

Instantly share code, notes, and snippets.

@rogeriochaves
Created January 17, 2013 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeriochaves/4552752 to your computer and use it in GitHub Desktop.
Save rogeriochaves/4552752 to your computer and use it in GitHub Desktop.
Just trying to simulate jquery like methods binding with ruby
class JQuery
class << self
attr_accessor :thread
end
def self.get(url, &block)
block.call("resposta")
return self
end
def self.error(&block)
block.call("erro")
return self
end
attr_accessor :attributes
def initialize
self.attributes = {href: 'http://www.google.com/'}
end
def attr(get, set = nil)
return self.attributes[get] if !set
self.attributes[get] = set
return self
end
end
def JQuery(selector)
return JQuery.new
end
(JQuery.get 'site' do |data|
puts data
end).error do |data|
puts data
end
puts JQuery(".classe #id").attr(:href)
elem = JQuery(".classe #id")
elem.attr(:href, 'http://www.github.com/')
puts elem.attr(:href)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment