Skip to content

Instantly share code, notes, and snippets.

@matthewrudy
Last active June 26, 2019 22:30
Show Gist options
  • Save matthewrudy/62bf3be9580fc03566318c40fff79aee to your computer and use it in GitHub Desktop.
Save matthewrudy/62bf3be9580fc03566318c40fff79aee to your computer and use it in GitHub Desktop.
Example of a module that expects the classes including it to have certain methods implemented
# typed: true
class AdminLogin
include Loginable
def email
'[email protected]'
end
end
module Loginable
include Kernel
def log_in!(password)
puts <<~MSG
logging in:
email: #{email}
password: #{password}
MSG
end
# sometimes I do this
# but not all circumstances make sense
#
# def email
# raise NotImplementedError
# end
# this is a hack to make it pass
# but is annoying if you don't own the method signature
#
# def email
# super
# end
end
editor.rb:17: Method email does not exist on Loginable https://srb.help/7003
17 | email: #{email}
^^^^^
https://github.com/sorbet/sorbet/tree/90c20f728c528aa4a1a3dc1a137e4c9eae95716d/rbi/core/kernel.rbi#L96: Did you mean: Kernel#eval?
96 | def eval(arg0, arg1=T.unsafe(nil), filename=T.unsafe(nil), lineno=T.unsafe(nil)); end
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment