Created
January 17, 2013 01:29
-
-
Save rogeriochaves/4552752 to your computer and use it in GitHub Desktop.
Just trying to simulate jquery like methods binding with ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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