Open sudo-nice opened 5 years ago
Another example:
require "option_parser"
module Opts
extend self
class_property foos = [] of String
class_property bar : String?
def parse(args)
OptionParser.parse(args) do |opts|
opts.on("--foo FOO", "It's foo") { |o| foos << o }
opts.on("--bar BAR", "It's bar") { |o| bar = o }
# But would work this way:
# opts.on("--bar BAR", "It's bar") { |o| Opts.bar = o }
end
end
end
Opts.parse %w[--foo foo_arg --bar bar_arg]
p Opts.foos # => ["foo_arg"]
p Opts.bar # => nil (but expected to be "bar_arg")
Reduced:
def foo(&)
yield 1
end
module Foo
@@x = 2
foo { |y| @@x = y } # Error: undefined method 'y' for Foo:Module
end
This code fails to compile:
Weird error:
But this works:
Crystal 0.27.0 [c9d1eef8f] (2018-11-01)
LLVM: 4.0.0 Default target: x86_64-unknown-linux-gnu