sorbet

How would you do rose memoization with Sorbet?

两盒软妹~` 提交于 2021-01-27 13:33:43
问题 Trying to annotate this code, the rose memoization ( @||= ) gives me an error Use of undeclared variable @git_sha . # typed: strict # frozen_string_literal: true module Util extend T::Sig sig { returns(String) } def self.git_sha @git_sha ||= ENV.fetch( 'GIT_REV', `git rev-parse --verify HEAD 2>&1` ).chomp end end As far as I've found, I should declare the variable's type with T.let but haven't figured out specifically how. 回答1: Sorbet now has built-in support for this, as of 0.4.4679. Before

Is there a way to use Sorbet without adding the # type annotation to every file?

倖福魔咒の 提交于 2020-05-29 08:48:11
问题 I want to start using Sorbet for my Ruby on Rails project, but I've been asked not to add the type annotation to every file. Is there a way to use Sorbet without adding the annotation? 回答1: Sorbet supports --typed-override feature where you can give sorbet a YAML file to specify what files should go into what level: https://github.com/sorbet/sorbet/tree/master/test/cli/override-typed. srb runner doesn't currently know about it, but there has been chatter in the community about adding support

Is there a way to use Sorbet without adding the # type annotation to every file?

为君一笑 提交于 2020-05-29 08:47:50
问题 I want to start using Sorbet for my Ruby on Rails project, but I've been asked not to add the type annotation to every file. Is there a way to use Sorbet without adding the annotation? 回答1: Sorbet supports --typed-override feature where you can give sorbet a YAML file to specify what files should go into what level: https://github.com/sorbet/sorbet/tree/master/test/cli/override-typed. srb runner doesn't currently know about it, but there has been chatter in the community about adding support

syntax for methods using raise / throw in Sorbet

北战南征 提交于 2020-01-16 09:08:23
问题 Is there a way to specify which exceptions a method might raise , so it's known for which a rescue might be needed? In Java (Doc) it looks this way: void example(int: x) throws Exception { if x > 42 throw new Exception; } Maybe something like this!? → View on sorbet.run # typed: true extend T::Sig sig {params(x: Integer).void.raises(StandardError)} def example(x) raise RuntimeError if x > 42 end Don't get confused: Usual exceptions are handled using raise ... rescue in Ruby. begin raise