Module: RBS::UnitTest::WithAliases
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Convertibles
|
|
Defined in: | lib/rbs/unit_test/with_aliases.rb |
Instance Method Summary
- #with(*args, &block)
- #with_array(*elements) {|_ = elements| ... }
- #with_bool {|true| ... }
- #with_boolish(&block) (also: #with_untyped)
- #with_encoding(encoding = Encoding::UTF_8, &block)
- #with_float(value = 0.1) {|value| ... }
- #with_hash(hash = {}) {|_ = hash| ... }
- #with_int(value = 3) {|value| ... }
- #with_interned(value = :&, &block)
- #with_io(io = $stdout) {|io| ... }
- #with_path(path = "/tmp/foo.txt", &block)
- #with_range(start, stop, exclude_end = false)
- #with_string(value = '') {|value| ... }
-
#with_untyped(&block)
Alias for #with_boolish.
Instance Method Details
#with(*args, &block)
[ GitHub ]#with_array(*elements) {|_ = elements| ... }
#with_bool {|true| ... }
#with_boolish(&block) Also known as: #with_untyped
[ GitHub ]# File 'lib/rbs/unit_test/with_aliases.rb', line 111
def with_boolish(&block) return WithEnum.new to_enum(__method__ || raise) unless block with_bool(&block) [nil, 1, Object.new, BlankSlate.new, "hello, world!"].each(&block) end
#with_encoding(encoding = Encoding::UTF_8, &block)
[ GitHub ]# File 'lib/rbs/unit_test/with_aliases.rb', line 91
def with_encoding(encoding = Encoding::UTF_8, &block) return WithEnum.new to_enum(__method__ || raise, encoding) unless block block.call encoding with_string(encoding.to_s, &block) end
#with_float(value = 0.1) {|value| ... }
#with_hash(hash = {}) {|_ = hash| ... }
#with_int(value = 3) {|value| ... }
#with_interned(value = :&, &block)
[ GitHub ]# File 'lib/rbs/unit_test/with_aliases.rb', line 98
def with_interned(value = :&, &block) return WithEnum.new to_enum(__method__ || raise, value) unless block with_string(value.to_s, &block) block.call value.to_sym end
#with_io(io = $stdout) {|io| ... }
#with_path(path = "/tmp/foo.txt", &block)
[ GitHub ]# File 'lib/rbs/unit_test/with_aliases.rb', line 84
def with_path(path = "/tmp/foo.txt", &block) return WithEnum.new to_enum(__method__ || raise, path) unless block with_string(path, &block) block.call ToPath.new(path) end
#with_range(start, stop, exclude_end = false)
# File 'lib/rbs/unit_test/with_aliases.rb', line 119
def with_range(start, stop, exclude_end = false) # If you need fixed starting and stopping points, you can just do `with_range with(1), with(2)`. raise ArgumentError, '`start` must be from a `with` method' unless start.is_a? WithEnum raise ArgumentError, '`stop` must be from a `with` method' unless stop.is_a? WithEnum start.each do |lower| stop.each do |upper| yield CustomRange.new(lower, upper, exclude_end) # `Range` requires `begin <=> end` to return non-nil, but doesn't actually # end up using the return value of it. This is to add that in when needed. def lower.<=>(rhs) = :not_nil unless defined? lower.<=> # If `lower <=> rhs` is defined but nil, then that means we're going to be constructing # an illegal range (eg `3..ToInt.new(4)`). So, we need to skip yielding an invalid range # in that case. next if defined?(lower.<=>) && nil == (lower <=> upper) yield Range.new(lower, upper, exclude_end) end end end
#with_string(value = '') {|value| ... }
#with_untyped(&block)
Alias for #with_boolish.
# File 'lib/rbs/unit_test/with_aliases.rb', line 117
alias with_untyped with_boolish