Skip to content

Instantly share code, notes, and snippets.

@nasser
Created October 16, 2012 13:45
Show Gist options
  • Save nasser/3899382 to your computer and use it in GitHub Desktop.
Save nasser/3899382 to your computer and use it in GitHub Desktop.
Signature matching
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
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