Sha256: 8d714ea81ffcb6cde9d5a6a500dcc71105ec1a6a418e7d7c54c36ba4641bd1a7
Contents?: true
Size: 1.13 KB
Versions: 19
Compression:
Stored size: 1.13 KB
Contents
require File.expand_path("../example_setup", __FILE__) require "github/result" def do_something 1 end def do_something_that_errors raise "noooooppppeeeee" end result = GitHub::Result.new { do_something } p result.ok? # => true p result.value! # => 1 result = GitHub::Result.new { do_something_that_errors } p result.ok? # => false p result.value { "default when error happens" } # => "default when error happens" begin result.value! # => raises exception because error happened rescue => error p result.error # => the error p error # the same error end # Outputs Step 1, 2, 3 result = GitHub::Result.new { GitHub::Result.new { puts "Step 1: success!" } }.then { |value| GitHub::Result.new { puts "Step 2: success!" } }.then { |value| GitHub::Result.new { puts "Step 3: success!" } } p result.ok? # => true # Outputs Step 1, 2 and stops. result = GitHub::Result.new { GitHub::Result.new { puts "Step 1: success!" } }.then { |value| GitHub::Result.new { puts "Step 2: failed!" raise } }.then { |value| GitHub::Result.new { puts "Step 3: should not get here because previous step failed!" } } p result.ok? # => false
Version data entries
19 entries across 19 versions & 1 rubygems