Created
November 20, 2017 18:04
-
-
Save RyanScottLewis/458d7db9b3aba2fcb4ab08de9964a1c7 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
# Code | |
abstract class Interface | |
def initialize | |
end | |
property! application : Application | |
abstract def call | |
end | |
class Interface::CommandLine < Interface | |
def call | |
puts "Running application through the command-line interface." if @application.verbose | |
end | |
end | |
class Interface::Graphical < Interface | |
def call | |
puts "Running application through the graphical interface." if @application.verbose | |
end | |
end | |
class Application | |
def self.call(interface : Interface) | |
new(interface).call | |
end | |
def initialize(@interface : Interface) | |
@interface.application = self | |
end | |
getter verbose : Bool = true | |
getter interface : Interface | |
delegate call, to: @interface | |
end | |
Application.call(Interface::CommandLine.new) | |
# Error: | |
# | |
# Error in examples/app_problem.cr:48: instantiating 'Application:Class#call(Interface::CommandLine)' | |
# | |
# Application.call(Interface::CommandLine.new) | |
# ^~~~ | |
# | |
# in examples/app_problem.cr:33: instantiating 'Application#call()' | |
# | |
# new(interface).call | |
# ^~~~ | |
# | |
# in examples/app_problem.cr:43: expanding macro | |
# | |
# delegate call, to: @interface | |
# ^ | |
# | |
# in macro 'delegate' /usr/local/Cellar/crystal-lang/0.23.1_3/src/object.cr:1067, line 3: | |
# | |
# 1. | |
# 2. def call(*args, **options) | |
# > 3. @interface.call(*args, **options) | |
# 4. end | |
# 5. | |
# 6. def call(*args, **options) | |
# 7. @interface.call(*args, **options) do |*yield_args| | |
# 8. yield *yield_args | |
# 9. end | |
# 10. end | |
# 11. | |
# 12. | |
# | |
# instantiating 'Interface+#call(Tuple(), NamedTuple())' | |
# in examples/app_problem.cr:25: undefined method 'verbose' for Nil (compile-time type is (Application | Nil)) | |
# | |
# puts "Running application through the graphical interface." if @application.verbose | |
# ^~~~~~~ | |
# | |
# Rerun with --error-trace to show a complete error trace. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment