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
| def a(val) | |
| val += 1 | |
| lambda { return val }.call | |
| val += 1 | |
| end | |
| val = a(1) | |
| p val # => 3 |
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
| class NotAnError | |
| end | |
| raise NotAnError |
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
| class PolicyError < Exception | |
| end | |
| class UserPolicyError < PolicyError | |
| end | |
| begin | |
| raise PolicyError, 'access not granted' | |
| rescue PolicyError => policy_error | |
| puts "#{policy_error.class}: #{policy_error.message}" |
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
| i = 0 | |
| begin | |
| i += 1 | |
| puts "retry ##{i}" | |
| raise RuntimeError | |
| rescue RuntimeError => e | |
| retry if i < 3 | |
| end |
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
| begin | |
| "my string".odd? | |
| rescue NoMethodError => e | |
| puts "#{$!.class}: #{$!.message}" | |
| $@.each { |loc| puts loc } | |
| # SAME AS | |
| # puts "#{e.class}: #{e.message}" | |
| # e.backtrace.each { |loc| puts loc } | |
| end |
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
| begin | |
| 3 / 0 | |
| rescue ZeroDivisionError => e | |
| puts "#{e.class}: #{e.message}" | |
| end | |
| begin | |
| "my string".odd? | |
| rescue NoMethodError => e | |
| puts "#{e.class}: #{e.message}" |
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
| begin | |
| raise NoMethodError, 'an error occurred' | |
| rescue NoMethodError => e | |
| puts "#{e.class}: #{e.message}" | |
| end |
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
| while gets | |
| puts "line: #{$_}" | |
| end |
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
| p $VERBOSE | |
| warn 'printed' | |
| def test | |
| end | |
| def test | |
| end |
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
| p $VERBOSE | |
| warn 'printed' | |
| { my_key: 'value', my_key: 'another_value' } |