Created
October 16, 2012 13:45
-
-
Save nasser/3899382 to your computer and use it in GitHub Desktop.
Signature matching
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 Signature | |
def self.[] *sig | |
Signature.new sig | |
end | |
def initialize sig | |
@signature = sig | |
end | |
def === other | |
return false if other.length != @signature.length | |
@signature.zip(other).map { |match, argument| | |
case match | |
when Symbol; argument.respond_to? match | |
else; match === argument | |
end | |
}.all? | |
end | |
end |
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
def initialize *args | |
@pointer = Native.ofimage_new | |
case args | |
when Signature[] | |
when Signature[:to_s] | |
load args.first | |
when Signature[:to_f, :to_f] | |
resize *args | |
when Signature[:to_s, Fixnum, Boolean] | |
file, quality, texture = args | |
load file, quality | |
use_texture texture | |
else | |
raise ArgumentError, args.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment