You can add guard at the beginning of the function and throw an exception if the arguments are invalid. For instance:
def my_method(number) fail ArgumentError, "Input should be greater than or equal to 2" if number < 2
You can define a custom exception class if you do not want to use ArgumentError
If you are building something like a framework, then you can use metaprogramming methods to intercept method calls and apply some validations. Refer to Code Execution for each method call in the Ruby module . You may need to come up with some kind of DSL to express these checks - a typical example of a DSL check is Active Record Validations in Rails.
In general, for everyday use cases just raise ( or fail ) and rescue enough. Verifications based on metaprograms and DSL are only necessary if you are creating a general-purpose infrastructure.
source share