Created
September 23, 2010 20:50
-
-
Save pcapriotti/594336 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def on(sig, types = nil, &blk) | |
sig = Signal.create(sig, types) | |
candidates = if is_a? Qt::Object | |
signal_map[sig.symbol] | |
end | |
if candidates | |
if types | |
# find candidate with the correct argument types | |
candidates = candidates.find_all{|s| s[1] == types } | |
end | |
if candidates.size > 1 | |
# find candidate with the correct arity | |
arity = blk.arity | |
if blk.arity == -1 | |
# take first | |
candidates = [candidates.first] | |
else | |
candidates = candidates.find_all{|s| s[1].size == arity } | |
end | |
end | |
if candidates.size > 1 | |
raise "Ambiguous overload for #{sig} with arity #{arity}" | |
elsif candidates.empty? | |
msg = if types | |
"with types #{types.join(' ')}" | |
else | |
"with arity #{blk.arity}" | |
end | |
raise "No overload for #{sig} #{msg}" | |
end | |
sign = SIGNAL(candidates.first[0]) | |
connect(sign, &blk) | |
SignalDisconnecter.new(self, sign) | |
else | |
observer = observe(sig.symbol, &blk) | |
ObserverDisconnecter.new(self, observer) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment