TIL: Ruby Warnings
Ruby warnings
Ruby has a built in warning mechanism in Kernel#warn
.
class Foo
def deprecated_method
warn('The `deprecated_method` is deprecated, use `not_deprecated` instead.', uplevel: 1)
not_deprecated
end
def not_deprecated
end
end
The uplevel: 1
gives information about the current frame of execution (the filename and line number). Super useful for deprecating methods.
Note though, all warning can be supressed if warning have been disabled for the runtime, e.g. through the -W0
flag.
Member discussion