Created
December 13, 2008 01:35
-
-
Save lukesutton/35373 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
| # Check types | |
| def type_check(checks) | |
| checks.each do |var, types| | |
| types = types.is_a? Array ? types : [types] | |
| match = false | |
| types.each { |type| match = true if var.is_a? type } | |
| raise ArgumentError unless match | |
| end | |
| end | |
| # Usage | |
| def self.localized_tree(locale, dialect, page_opts = {}) | |
| type_check( | |
| locale => [Locale, Numeric], | |
| dialect => [Dialect, Numeric], | |
| page_opts => Hash | |
| ) | |
| # Do some other stuff | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment